UNPKG

@vue/eslint-config-airbnb

Version:
238 lines (193 loc) 10.9 kB
// Ref: https://github.com/airbnb/javascript/blob/master/packages/eslint-config-airbnb/rules/react.js module.exports = { parser: require.resolve('vue-eslint-parser'), parserOptions: { ecmaFeatures: { jsx: true, }, }, plugins: ['react', 'vue'], settings: { // This is only to suppress the missing React version warning // https://github.com/jsx-eslint/eslint-plugin-react/blob/91398309901960d2ea41a9d62a2896981268cb1d/lib/util/version.js#L88-L92 // TODO: fork it to create a universal eslint-plugin-jsx react: { version: '999.999.999', }, }, rules: { // Specify whether double or single quotes should be used in JSX attributes // https://eslint.org/docs/rules/jsx-quotes 'jsx-quotes': ['error', 'prefer-double'], // Enforce boolean attributes notation in JSX // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-boolean-value.md 'react/jsx-boolean-value': ['error', 'never', { always: [] }], // Validate closing bracket location in JSX // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-closing-bracket-location.md 'react/jsx-closing-bracket-location': ['error', 'line-aligned'], // Validate closing tag location in JSX // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-closing-tag-location.md 'react/jsx-closing-tag-location': 'error', // Enforce or disallow spaces inside of curly braces in JSX attributes // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-curly-spacing.md 'react/jsx-curly-spacing': ['error', 'never', { allowMultiline: true }], // Validate props indentation in JSX // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-indent-props.md 'react/jsx-indent-props': ['error', 2], // Limit maximum of props on a single line in JSX // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-max-props-per-line.md 'react/jsx-max-props-per-line': ['error', { maximum: 1, when: 'multiline' }], // Prevent usage of .bind() in JSX props // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-no-bind.md 'react/jsx-no-bind': ['error', { // Vue's template ref isn't the same as React's ref, so this option doesn't make sense ignoreRefs: false, allowArrowFunctions: true, allowFunctions: false, allowBind: false, ignoreDOMComponents: true, }], // Prevent duplicate props in JSX // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-no-duplicate-props.md 'react/jsx-no-duplicate-props': ['error', { ignoreCase: true }], // Disallow undeclared variables in JSX // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-no-undef.md // FIXME: should check if this works well without setting the pragma // https://github.com/typescript-eslint/typescript-eslint/issues/3788 // 'react/jsx-no-undef': 'error', // Enforce PascalCase for user-defined JSX components // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-pascal-case.md 'react/jsx-pascal-case': ['error', { allowAllCaps: true, ignore: [], }], // Prevent variables used in JSX to be incorrectly marked as unused // https://eslint.vuejs.org/rules/jsx-uses-vars.html // Already in `plugin:vue/base` ruleset. // Adding it again here to keep consistency with the upstream JSX rules 'vue/jsx-uses-vars': 'error', // https://eslint.vuejs.org/rules/comment-directive.html // Already in `plugin:vue/base` ruleset. // Now that we add `vue/jsx-uses-vars`, // I think it's more consistent to add this rule explicitly too. 'vue/comment-directive': 'error', // Skipped `react/no-unknown-property`. // Because Vue JSX doesn't suffer the same casing issue as React JSX // ... skipped other React-specific rules // https://eslint.vuejs.org/rules/require-render-return.html // Already in `plugin:vue/essential` and `plugin:vue/vue3-essential` ruleset. // Adding it again here to keep consistency with the upstream JSX rules 'vue/require-render-return': 'error', // Prevent extra closing tags for components without children // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/self-closing-comp.md 'react/self-closing-comp': 'error', // Prevent missing parentheses around multilines JSX // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-wrap-multilines.md 'react/jsx-wrap-multilines': ['error', { declaration: 'parens-new-line', assignment: 'parens-new-line', return: 'parens-new-line', arrow: 'parens-new-line', condition: 'parens-new-line', logical: 'parens-new-line', prop: 'parens-new-line', }], // Require that the first prop in a JSX element be on a new line when the element is multiline // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-first-prop-new-line.md 'react/jsx-first-prop-new-line': ['error', 'multiline-multiprop'], // Enforce spacing around jsx equals signs // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-equals-spacing.md 'react/jsx-equals-spacing': ['error', 'never'], // Enforce JSX indentation // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-indent.md 'react/jsx-indent': ['error', 2], // Disallow target="_blank" on links // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-no-target-blank.md 'react/jsx-no-target-blank': ['error', { // Unllike in the `airbnb-base` ruleset, this is set to `true`, // Because neither Vue CLI & Vite targets IE 11 by default. allowReferrer: true, enforceDynamicLinks: 'always', }], // only .jsx files may have JSX // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-filename-extension.md // TODO: (semver-major) shall we forbid JSX in `.vue` by default? 'react/jsx-filename-extension': ['error', { extensions: ['.jsx', '.vue'] }], // prevent accidental JS comments from being injected into JSX as text // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-no-comment-textnodes.md 'react/jsx-no-comment-textnodes': 'error', // Skipped `react/no-danger-with-children` // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-danger-with-children.md // Need a Vue-JSX port that does the same job as https://eslint.vuejs.org/rules/no-child-content.html // Require style prop value be an object or var // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/style-prop-object.md 'react/style-prop-object': 'error', // Prevent invalid characters from appearing in markup // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-unescaped-entities.md 'react/no-unescaped-entities': 'error', // Prevent passing of children as props // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-children-prop.md 'react/no-children-prop': 'error', // Validate whitespace in and around the JSX opening and closing brackets // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-tag-spacing.md 'react/jsx-tag-spacing': ['error', { closingSlash: 'never', beforeSelfClosing: 'always', afterOpening: 'never', beforeClosing: 'never', }], // Prevent usage of Array index in keys // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-array-index-key.md 'react/no-array-index-key': 'error', // Prevent void DOM elements from receiving children // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/void-dom-elements-no-children.md 'react/void-dom-elements-no-children': 'error', // Enforce curly braces or disallow unnecessary curly braces in JSX props and/or children // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-curly-brace-presence.md 'react/jsx-curly-brace-presence': ['error', { props: 'never', children: 'never' }], // One JSX Element Per Line // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-one-expression-per-line.md 'react/jsx-one-expression-per-line': ['error', { allow: 'single-child' }], // Prevent usage of button elements without an explicit type attribute // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/button-has-type.md 'react/button-has-type': ['error', { button: true, submit: true, reset: false, }], // Disallow multiple spaces between inline JSX props // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-props-no-multi-spaces.md 'react/jsx-props-no-multi-spaces': 'error', // Enforce shorthand form for fragments // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-fragments.md 'react/jsx-fragments': ['error', 'syntax'], // Enforce linebreaks in curly braces in JSX attributes and expressions. // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-curly-newline.md 'react/jsx-curly-newline': ['error', { multiline: 'consistent', singleline: 'consistent', }], // Disallow JSX props spreading // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-props-no-spreading.md 'react/jsx-props-no-spreading': ['error', { html: 'enforce', custom: 'enforce', explicitSpread: 'ignore', exceptions: [], }], // Prevent usage of `javascript:` URLs // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-no-script-url.md 'react/jsx-no-script-url': 'error', // Disallow unnecessary fragments // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-no-useless-fragment.md 'react/jsx-no-useless-fragment': 'error', // Skipped `react/no-unstable-nested-components` for now, // because I'm not sure whether it works correctly for Vue render functions. // Enforce that namespaces are not used in Vue elements // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-namespace.md 'react/no-namespace': 'error', // Prevent usage of invalid attributes // https://github.com/jsx-eslint/eslint-plugin-react/blob/21e01b61af7a38fc86d94f27eb66cda8054582ed/docs/rules/no-invalid-html-attribute.md 'react/no-invalid-html-attribute': 'error', }, };