Skip to content

Commit

Permalink
Framework: Try to extract shared eslint config (#5502)
Browse files Browse the repository at this point in the history
  • Loading branch information
gziolo authored Mar 12, 2018
1 parent 8a4d644 commit 7d8fb68
Show file tree
Hide file tree
Showing 3 changed files with 176 additions and 327 deletions.
153 changes: 2 additions & 151 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,90 +18,20 @@ const majorMinorRegExp = escapeRegExp( version.replace( /\.\d+$/, '' ) ) + '(\\.

module.exports = {
root: true,
parser: 'babel-eslint',
extends: [
'wordpress',
'plugin:react/recommended',
'plugin:jsx-a11y/recommended',
'plugin:jest/recommended',
'./eslint/config.js',
'plugin:jest/recommended'
],
env: {
browser: false,
es6: true,
node: true,
'jest/globals': true,
},
parserOptions: {
sourceType: 'module',
ecmaFeatures: {
jsx: true,
},
},
globals: {
wp: true,
wpApiSettings: true,
window: true,
document: true,
},
plugins: [
'wordpress',
'react',
'jsx-a11y',
'jest',
],
settings: {
react: {
pragma: 'wp',
},
},
rules: {
'array-bracket-spacing': [ 'error', 'always' ],
'brace-style': [ 'error', '1tbs' ],
camelcase: [ 'error', { properties: 'never' } ],
'comma-dangle': [ 'error', 'always-multiline' ],
'comma-spacing': 'error',
'comma-style': 'error',
'computed-property-spacing': [ 'error', 'always' ],
'constructor-super': 'error',
'dot-notation': 'error',
'eol-last': 'error',
eqeqeq: 'error',
'func-call-spacing': 'error',
indent: [ 'error', 'tab', { SwitchCase: 1 } ],
'jsx-a11y/label-has-for': [ 'error', {
required: 'id',
} ],
'jsx-a11y/media-has-caption': 'off',
'jsx-a11y/no-noninteractive-tabindex': 'off',
'jsx-a11y/role-has-required-aria-props': 'off',
'jsx-quotes': 'error',
'key-spacing': 'error',
'keyword-spacing': 'error',
'lines-around-comment': 'off',
'no-alert': 'error',
'no-bitwise': 'error',
'no-caller': 'error',
'no-console': 'error',
'no-const-assign': 'error',
'no-debugger': 'error',
'no-dupe-args': 'error',
'no-dupe-class-members': 'error',
'no-dupe-keys': 'error',
'no-duplicate-case': 'error',
'no-duplicate-imports': 'error',
'no-else-return': 'error',
'no-eval': 'error',
'no-extra-semi': 'error',
'no-fallthrough': 'error',
'no-lonely-if': 'error',
'no-mixed-operators': 'error',
'no-mixed-spaces-and-tabs': 'error',
'no-multiple-empty-lines': [ 'error', { max: 1 } ],
'no-multi-spaces': 'error',
'no-multi-str': 'off',
'no-negated-in-lhs': 'error',
'no-nested-ternary': 'error',
'no-redeclare': 'error',
'no-restricted-syntax': [
'error',
{
Expand Down Expand Up @@ -148,89 +78,10 @@ module.exports = {
selector: 'ImportDeclaration[source.value=/^viewport$/]',
message: 'Use @wordpress/viewport as import path instead.',
},
{
selector: 'CallExpression[callee.name=/^__|_n|_x$/]:not([arguments.0.type=/^Literal|BinaryExpression$/])',
message: 'Translate function arguments must be string literals.',
},
{
selector: 'CallExpression[callee.name=/^_n|_x$/]:not([arguments.1.type=/^Literal|BinaryExpression$/])',
message: 'Translate function arguments must be string literals.',
},
{
selector: 'CallExpression[callee.name=_nx]:not([arguments.2.type=/^Literal|BinaryExpression$/])',
message: 'Translate function arguments must be string literals.',
},
{
selector: 'CallExpression[callee.name="deprecated"] Property[key.name="version"][value.value=/' + majorMinorRegExp + '/]',
message: 'Deprecated functions must be removed before releasing this version.',
},
],
'no-shadow': 'error',
'no-undef': 'error',
'no-undef-init': 'error',
'no-unreachable': 'error',
'no-unsafe-negation': 'error',
'no-unused-expressions': 'error',
'no-unused-vars': 'error',
'no-useless-computed-key': 'error',
'no-useless-constructor': 'error',
'no-useless-return': 'error',
'no-var': 'error',
'no-whitespace-before-property': 'error',
'object-curly-spacing': [ 'error', 'always' ],
'padded-blocks': [ 'error', 'never' ],
'prefer-const': 'error',
'quote-props': [ 'error', 'as-needed' ],
'react/display-name': 'off',
'react/jsx-curly-spacing': [ 'error', {
when: 'always',
children: true,
} ],
'react/jsx-equals-spacing': 'error',
'react/jsx-indent': [ 'error', 'tab' ],
'react/jsx-indent-props': [ 'error', 'tab' ],
'react/jsx-key': 'error',
'react/jsx-tag-spacing': 'error',
'react/no-children-prop': 'off',
'react/no-find-dom-node': 'warn',
'react/prop-types': 'off',
semi: 'error',
'semi-spacing': 'error',
'space-before-blocks': [ 'error', 'always' ],
'space-before-function-paren': [ 'error', 'never' ],
'space-in-parens': [ 'error', 'always' ],
'space-infix-ops': [ 'error', { int32Hint: false } ],
'space-unary-ops': [ 'error', {
overrides: {
'!': true,
},
} ],
'template-curly-spacing': [ 'error', 'always' ],
'valid-jsdoc': [ 'error', {
prefer: {
arg: 'param',
argument: 'param',
extends: 'augments',
returns: 'return',
},
preferType: {
array: 'Array',
bool: 'boolean',
Boolean: 'boolean',
float: 'number',
Float: 'number',
int: 'number',
integer: 'number',
Integer: 'number',
Number: 'number',
object: 'Object',
String: 'string',
Void: 'void',
},
requireParamDescription: false,
requireReturn: false,
} ],
'valid-typeof': 'error',
yoda: 'off',
},
};
165 changes: 165 additions & 0 deletions eslint/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
module.exports = {
parser: 'babel-eslint',
extends: [
'wordpress',
'plugin:react/recommended',
'plugin:jsx-a11y/recommended',
],
env: {
browser: false,
es6: true,
node: true,
},
parserOptions: {
sourceType: 'module',
ecmaFeatures: {
jsx: true,
},
},
globals: {
wp: true,
window: true,
document: true,
},
plugins: [
'wordpress',
'react',
'jsx-a11y',
],
settings: {
react: {
pragma: 'wp',
},
},
rules: {
'array-bracket-spacing': [ 'error', 'always' ],
'brace-style': [ 'error', '1tbs' ],
camelcase: [ 'error', { properties: 'never' } ],
'comma-dangle': [ 'error', 'always-multiline' ],
'comma-spacing': 'error',
'comma-style': 'error',
'computed-property-spacing': [ 'error', 'always' ],
'constructor-super': 'error',
'dot-notation': 'error',
'eol-last': 'error',
eqeqeq: 'error',
'func-call-spacing': 'error',
indent: [ 'error', 'tab', { SwitchCase: 1 } ],
'jsx-a11y/label-has-for': [ 'error', {
required: 'id',
} ],
'jsx-a11y/media-has-caption': 'off',
'jsx-a11y/no-noninteractive-tabindex': 'off',
'jsx-a11y/role-has-required-aria-props': 'off',
'jsx-quotes': 'error',
'key-spacing': 'error',
'keyword-spacing': 'error',
'lines-around-comment': 'off',
'no-alert': 'error',
'no-bitwise': 'error',
'no-caller': 'error',
'no-console': 'error',
'no-const-assign': 'error',
'no-debugger': 'error',
'no-dupe-args': 'error',
'no-dupe-class-members': 'error',
'no-dupe-keys': 'error',
'no-duplicate-case': 'error',
'no-duplicate-imports': 'error',
'no-else-return': 'error',
'no-eval': 'error',
'no-extra-semi': 'error',
'no-fallthrough': 'error',
'no-lonely-if': 'error',
'no-mixed-operators': 'error',
'no-mixed-spaces-and-tabs': 'error',
'no-multiple-empty-lines': [ 'error', { max: 1 } ],
'no-multi-spaces': 'error',
'no-multi-str': 'off',
'no-negated-in-lhs': 'error',
'no-nested-ternary': 'error',
'no-redeclare': 'error',
'no-restricted-syntax': [
'error',
{
selector: 'CallExpression[callee.name=/^__|_n|_x$/]:not([arguments.0.type=/^Literal|BinaryExpression$/])',
message: 'Translate function arguments must be string literals.',
},
{
selector: 'CallExpression[callee.name=/^_n|_x$/]:not([arguments.1.type=/^Literal|BinaryExpression$/])',
message: 'Translate function arguments must be string literals.',
},
{
selector: 'CallExpression[callee.name=_nx]:not([arguments.2.type=/^Literal|BinaryExpression$/])',
message: 'Translate function arguments must be string literals.',
},
],
'no-shadow': 'error',
'no-undef': 'error',
'no-undef-init': 'error',
'no-unreachable': 'error',
'no-unsafe-negation': 'error',
'no-unused-expressions': 'error',
'no-unused-vars': 'error',
'no-useless-computed-key': 'error',
'no-useless-constructor': 'error',
'no-useless-return': 'error',
'no-var': 'error',
'no-whitespace-before-property': 'error',
'object-curly-spacing': [ 'error', 'always' ],
'padded-blocks': [ 'error', 'never' ],
'prefer-const': 'error',
'quote-props': [ 'error', 'as-needed' ],
'react/display-name': 'off',
'react/jsx-curly-spacing': [ 'error', {
when: 'always',
children: true,
} ],
'react/jsx-equals-spacing': 'error',
'react/jsx-indent': [ 'error', 'tab' ],
'react/jsx-indent-props': [ 'error', 'tab' ],
'react/jsx-key': 'error',
'react/jsx-tag-spacing': 'error',
'react/no-children-prop': 'off',
'react/no-find-dom-node': 'warn',
'react/prop-types': 'off',
semi: 'error',
'semi-spacing': 'error',
'space-before-blocks': [ 'error', 'always' ],
'space-before-function-paren': [ 'error', 'never' ],
'space-in-parens': [ 'error', 'always' ],
'space-infix-ops': [ 'error', { int32Hint: false } ],
'space-unary-ops': [ 'error', {
overrides: {
'!': true,
},
} ],
'template-curly-spacing': [ 'error', 'always' ],
'valid-jsdoc': [ 'error', {
prefer: {
arg: 'param',
argument: 'param',
extends: 'augments',
returns: 'return',
},
preferType: {
array: 'Array',
bool: 'boolean',
Boolean: 'boolean',
float: 'number',
Float: 'number',
int: 'number',
integer: 'number',
Integer: 'number',
Number: 'number',
object: 'Object',
String: 'string',
Void: 'void',
},
requireParamDescription: false,
requireReturn: false,
} ],
'valid-typeof': 'error',
yoda: 'off',
},
};
Loading

0 comments on commit 7d8fb68

Please sign in to comment.