JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 11
  • Score
    100M100P100Q46509F
  • License MIT

Official ESLint plugin for Kdu

Package Exports

  • eslint-plugin-kdu
  • eslint-plugin-kdu/lib/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (eslint-plugin-kdu) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

eslint-plugin-kdu

Official ESLint plugin for Kdu

❕ Requirements

  • ESLint >=3.18.0.
    • >=4.7.0 to use eslint --fix.
    • >=4.14.0 to use with babel-eslint.
  • Node.js >=4.0.0

💿 Installation

npm install --save-dev eslint eslint-plugin-kdu

🚀 Usage

Create .eslintrc.* file to configure rules. See also: http://eslint.org/docs/user-guide/configuring.

Example .eslintrc.js:

module.exports = {
  extends: [
    // add more generic rulesets here, such as:
    // 'eslint:recommended',
    'plugin:kdu/essential'
  ],
  rules: {
    // override/add rules settings here, such as:
    // 'kdu/no-unused-vars': 'error'
  }
}

Attention

All component-related rules are being applied to code that passes any of the following checks:

  • Kdu.component() expression
  • Kdu.extend() expression
  • Kdu.mixin() expression
  • export default {} in .kdu or .jsx file

If you however want to take advantage of our rules in any of your custom objects that are Kdu components, you might need to use special comment // @kdu/component that marks object in the next line as a Kdu component in any file, e.g.:

// @kdu/component
const CustomComponent = {
  name: 'custom-component',
  template: '<div></div>'
}
Kdu.component('AsyncComponent', (resolve, reject) => {
  setTimeout(() => {
    // @kdu/component
    resolve({
      name: 'async-component',
      template: '<div></div>'
    })
  }, 500)
})

eslint-disable functionality in <template>

You can use <!-- eslint-disable -->-like HTML comments in <template> of .kdu files. For example:

<template>
  <!-- eslint-disable-next-line kdu/max-attributes-per-line -->
  <div a="1" b="2" c="3" d="4">
  </div>
</template>

If you want to disallow eslint-disable functionality, please disable kdu/comment-directive rule.

⚙️ Configs

This plugin provides four predefined configs:

  • plugin:kdu/base - Settings and rules to enable correct ESLint parsing
  • plugin:kdu/essential - Above, plus rules to prevent errors or unintended behavior
  • plugin:kdu/strongly-recommended - Above, plus rules to considerably improve code readability and/or dev experience
  • plugin:kdu/recommended - Above, plus rules to enforce subjective community defaults to ensure consistency

💡 Rules

Rules are grouped by priority to help you understand their purpose. The --fix option on the command line automatically fixes problems reported by rules which have a wrench 🔧 below.

Base Rules (Enabling Correct ESLint Parsing)

Enforce all the rules in this category, as well as all higher priority rules, with:

{
  "extends": "plugin:kdu/base"
}
Rule ID Description
kdu/comment-directive support comment-directives in <template>
kdu/jsx-uses-vars prevent variables used in JSX to be marked as unused

Priority A: Essential (Error Prevention)

Enforce all the rules in this category, as well as all higher priority rules, with:

{
  "extends": "plugin:kdu/essential"
}
Rule ID Description
kdu/no-async-in-computed-properties disallow asynchronous actions in computed properties
kdu/no-dupe-keys disallow duplication of field names
kdu/no-duplicate-attributes disallow duplication of attributes
kdu/no-parsing-error disallow parsing errors in <template>
kdu/no-reserved-keys disallow overwriting reserved keys
🔧 kdu/no-shared-component-data enforce component's data property to be a function
kdu/no-side-effects-in-computed-properties disallow side effects in computed properties
kdu/no-template-key disallow key attribute on <template>
kdu/no-textarea-mustache disallow mustaches in <textarea>
kdu/no-unused-vars disallow unused variable definitions of v-for directives or scope attributes
kdu/require-component-is require v-bind:is of <component> elements
kdu/require-render-return enforce render function to always return value
kdu/require-v-for-key require v-bind:key with v-for directives
kdu/require-valid-default-prop enforce props default values to be valid
kdu/return-in-computed-property enforce that a return statement is present in computed property
kdu/valid-template-root enforce valid template root
kdu/valid-v-bind enforce valid v-bind directives
kdu/valid-v-cloak enforce valid v-cloak directives
kdu/valid-v-else-if enforce valid v-else-if directives
kdu/valid-v-else enforce valid v-else directives
kdu/valid-v-for enforce valid v-for directives
kdu/valid-v-html enforce valid v-html directives
kdu/valid-v-if enforce valid v-if directives
kdu/valid-v-model enforce valid v-model directives
kdu/valid-v-on enforce valid v-on directives
kdu/valid-v-once enforce valid v-once directives
kdu/valid-v-pre enforce valid v-pre directives
kdu/valid-v-show enforce valid v-show directives
kdu/valid-v-text enforce valid v-text directives

Enforce all the rules in this category, as well as all higher priority rules, with:

{
  "extends": "plugin:kdu/strongly-recommended"
}
Rule ID Description
🔧 kdu/attribute-hyphenation enforce attribute naming style in template
🔧 kdu/html-end-tags enforce end tag style
🔧 kdu/html-indent enforce consistent indentation in <template>
🔧 kdu/html-self-closing enforce self-closing style
🔧 kdu/max-attributes-per-line enforce the maximum number of attributes per line
🔧 kdu/mustache-interpolation-spacing enforce unified spacing in mustache interpolations
🔧 kdu/name-property-casing enforce specific casing for the name property in Kdu components
🔧 kdu/no-multi-spaces disallow multiple spaces
kdu/require-default-prop require default value for props
kdu/require-prop-types require type definitions in props
🔧 kdu/v-bind-style enforce v-bind directive style
🔧 kdu/v-on-style enforce v-on directive style

Enforce all the rules in this category, as well as all higher priority rules, with:

{
  "extends": "plugin:kdu/recommended"
}
Rule ID Description
🔧 kdu/attributes-order enforce order of attributes
🔧 kdu/html-quotes enforce quotes style of HTML attributes
kdu/no-confusing-v-for-v-if disallow confusing v-for and v-if on the same element
🔧 kdu/order-in-components enforce order of properties in components
kdu/this-in-template enforce usage of this in template

Uncategorized

Rule ID Description
🔧 kdu/html-closing-bracket-newline require or disallow a line break before tag's closing brackets
🔧 kdu/html-closing-bracket-spacing require or disallow a space before tag's closing brackets
🔧 kdu/prop-name-casing enforce specific casing for the Prop name in Kdu components
🔧 kdu/script-indent enforce consistent indentation in <script>

👫 FAQ

What is the "Use the latest kdu-eslint-parser" error?

The most rules of eslint-plugin-kdu require kdu-eslint-parser to check <template> ASTs.

Make sure you have one of the following settings in your .eslintrc:

  • "extends": ["plugin:kdu/recommended"]
  • "extends": ["plugin:kdu/base"]

If you already use other parser (e.g. "parser": "babel-eslint"), please move it into parserOptions, so it doesn't collide with the kdu-eslint-parser used by this plugin's configuration:

- "parser": "babel-eslint",
  "parserOptions": {
+     "parser": "babel-eslint",
      "ecmaVersion": 2017,
      "sourceType": "module"
  }

The kdu-eslint-parser uses the parser which is set by parserOptions.parser to parse scripts.

Why doesn't it work on .kdu file?

  1. Make sure you don't have eslint-plugin-html in your config. The eslint-plugin-html extracts the content from <script> tags, but eslint-kdu-plugin requires <script> tags and <template> tags in order to distinguish template and script in single file components.
  "plugins": [
    "kdu",
-   "html"
  ]
  1. Make sure your tool is set to lint .kdu files.
  • CLI targets only .js files by default. You have to specify additional extensions by --ext option or glob patterns. E.g. eslint "src/**/*.{js,kdu}" or eslint src --ext .kdu.
  • VSCode targets only JavaScript or HTML files by default. You have to add {"autoFix": true, "language": "kdu"} into eslint.validate entry.

⚓ Semantic Versioning Policy

This plugin follows semantic versioning and ESLint's Semantic Versioning Policy.

📰 Changelog

We're using GitHub Releases.

🍻 Contribution guide

In order to add a new rule, you should:

  • Create issue on GH with description of proposed rule
  • Generate a new rule using the official yeoman generator
  • Run npm start
  • Write test scenarios & implement logic
  • Describe the rule in the generated docs file
  • Make sure all tests are passing
  • Run npm run update in order to update readme and recommended configuration
  • Create PR and link created issue in description

We're more than happy to see potential contributions, so don't hesitate. If you have any suggestions, ideas or problems feel free to add new issue, but first please make sure your question does not repeat previous ones.

🔒 License

See the LICENSE file for license rights and limitations (MIT).