Skip to content

Commit

Permalink
Make yarn lint work
Browse files Browse the repository at this point in the history
- Removed apps from the workspaces; couldn't find another way to make it work :(
- Moved all the ESlint packages to the root, including typescript ones
- The schema-blocks ESlint configuration has to stay inside that package due to non-overridable config
- Schema-blocks `useCallback` didn't work nicely, so ignore those ESlint errors inline
- Override ESlint config to prevent too many changes: `no-prototype-builtins` and `comma-dangle` (disabled for functions)
- Added `.eslintrc` and `.yaml` to the 2 spaces indent rule in `.editorconfig`
- Fixed all ESlint errors still remaining
- Adjusted the max Eslint warnings to the current amount of warnings
  • Loading branch information
igorschoester committed Mar 9, 2021
1 parent e9d192c commit 2b2c5ab
Show file tree
Hide file tree
Showing 103 changed files with 533 additions and 4,854 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ trim_trailing_whitespace = true
[*\.txt]
trim_trailing_whitespace = false

[*\.{md,json,yml,xml,xml\.dist}]
[*\.{md,json,yml,yaml,xml,xml\.dist,eslintrc}]
indent_style = space
indent_size = 2

Expand Down
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

193 changes: 165 additions & 28 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,39 +1,176 @@
extends: yoast

parser: babel-eslint
parserOptions:
ecmaVersion: 2018
sourceType: module

settings:
react:
version: "16.8"

rules:
# Custom rules: only for temporary exceptions that should be removed over time
camelcase: 1
complexity: [1, 6]
brace-style: 1
max-statements: 1
no-shadow: 1
require-jsdoc: 1
react/jsx-no-bind: 1
react/jsx-no-target-blank: 1
react/no-access-state-in-setstate: 1
react/no-deprecated: 1
react/no-unused-prop-types: 1
react/prop-types: 1
react/require-default-props: 1
no-restricted-imports:
no-prototype-builtins: 0
comma-dangle:
- error
- name: react
message: Please use @wordpress/element instead. No need to import just for JSX.
- name: react-dom
message: Please use @wordpress/element instead.

# Disabled rules
# In the editor, we're using the pragma `wp.element.createElement`
react/react-in-jsx-scope: 0
- arrays: always-multiline
objects: always-multiline
imports: always-multiline
exports: always-multiline
functions: never

overrides:
- files:
- "js/tests/**/*.js"
- "packages/*/tests/**/*.js"
- "packages/*/spec/**/*.js"
# Temporary exclusion:
- "packages/components/a11y/tests/**/*.js"
env:
jest: true
rules:
no-restricted-imports: "off"
- files:
- "packages/js/**/*.js"
rules:
# Custom rules: only for temporary exceptions that should be removed over time
camelcase: 1
complexity: [ 1, 6 ]
brace-style: 1
max-statements: 1
no-shadow: 1
require-jsdoc: 1
react/jsx-no-bind: 1
react/jsx-no-target-blank: 1
react/no-access-state-in-setstate: 1
react/no-deprecated: 1
react/no-unused-prop-types: 1
react/prop-types: 1
react/require-default-props: 1
no-restricted-imports:
- error
- name: react
message: Please use @wordpress/element instead. No need to import just for JSX.
- name: react-dom
message: Please use @wordpress/element instead.

settings:
react:
version: "16.3"
# Disabled rules
# In the editor, we're using the pragma `wp.element.createElement`
react/react-in-jsx-scope: 0
- files:
- "packages/js/tests/**/*.js"
rules:
no-restricted-imports: 0
- files:
- "packages/schema-blocks/src/**"
env:
jest: true
rules:
new-cap: 0
complexity:
- 2
- 10
"@typescript-eslint/no-parameter-properties":
- 2
- allows:
- protected readonly
- private readonly
"@typescript-eslint/explicit-function-return-type": 0
"@typescript-eslint/no-use-before-define":
- error
- functions: false
no-constant-condition:
- error
- checkLoops: false
max-statements:
- 2
- 33
no-unused-vars: 'off'
"@typescript-eslint/no-unused-vars":
- error
- varsIgnorePattern: "^createElement$"
no-dupe-class-members: 'off'
indent: 'off'
"@typescript-eslint/indent":
- 2
- tab
- SwitchCase: 1
space-before-function-paren:
- error
- anonymous: never
named: never
asyncArrow: always
valid-jsdoc:
- error
- requireReturn: false
requireReturnType: false
requireParamType: false
react/react-in-jsx-scope: 0
- files:
- "packages/components/**/*.js"
rules:
react/jsx-no-bind: 1
react/require-default-props: 1
react/default-props-match-prop-types: 1
react/no-unused-prop-types: 1
require-jsdoc: 1
- files:
- "packages/configuration-wizard/**/*.js"
rules:
react/no-unused-prop-types: 1
react/jsx-no-bind: 1
react/no-access-state-in-setstate: 1
require-jsdoc: 1
- files:
- "packages/replacement-variable-editor/**/*.js"
rules:
react/jsx-no-bind: 1
react/require-default-props: 1
- files:
- "packages/search-metadata-previews/**/*.js"
rules:
react/jsx-no-bind: 1
react/no-unused-state: 1
react/no-access-state-in-setstate: 1
react/require-default-props: 1
react/default-props-match-prop-types: 1
- files:
- "packages/yoastseo/**/*.js"
rules:
complexity: 1
# Longer grace period for Yoast config.
no-shadow: [ 1, { "builtinGlobals": false, "hoist": "all", "allow": [ ] } ]
require-jsdoc: [ 1, { "require": { "MethodDefinition": true, "ClassDeclaration": true, "ArrowFunctionExpression": true, "FunctionExpression": true } } ]
no-useless-escape: 1
- files:
- "packages/analysis-report/**/*.js"
rules:
complexity: [ 1, 6 ]
// A wrapping label is not necessary when there already is an htmlFor attribute.
jsx-a11y/label-has-for: [ "error", { required: "id" } ]
require-jsdoc: 1
react/button-has-type: 1
react/default-props-match-prop-types: 1
react/no-unused-prop-types: 1
react/no-access-state-in-setstate: 1
react/no-unused-state: 1
react/jsx-no-bind: 1
react/jsx-no-target-blank: 1
react/require-default-props: 1
react/forbid-foreign-prop-types: 1
- files:
- "packages/yoast-components/**/*.js"
rules:
complexity: [ 1, 6 ]
// A wrapping label is not necessary when there already is an htmlFor attribute.
jsx-a11y/label-has-for: [ "error", { required: "id" } ]
require-jsdoc: 1
react/button-has-type: 1
react/default-props-match-prop-types: 1
react/no-unused-prop-types: 1
react/no-access-state-in-setstate: 1
react/no-unused-state: 1
react/jsx-no-bind: 1
react/jsx-no-target-blank: 1
react/require-default-props: 1
react/forbid-foreign-prop-types: 1
env:
jest: true
15 changes: 9 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
},
"workspaces": {
"packages": [
"packages/*",
"apps/*"
"packages/*"
],
"nohoist": [
"**/grunt-*",
Expand All @@ -45,8 +44,11 @@
"unlink-monorepo": "node config/yarn/unlink_monorepo.js",
"bump-monorepo-packages": "node config/yarn/bump_monorepo_packages.js"
},
"dependencies": {},
"devDependencies": {
"@slack/webhook": "^5.0.2",
"@typescript-eslint/eslint-plugin": "^2.15.0",
"@typescript-eslint/parser": "^2.15.0",
"@wordpress/babel-plugin-makepot": "^1.0.0",
"@wordpress/babel-preset-default": "^1.1.3",
"@wordpress/dependency-extraction-webpack-plugin": "^2.8.0",
Expand Down Expand Up @@ -75,9 +77,10 @@
"enzyme": "^3.3.0",
"enzyme-adapter-react-16": "^1.5.0",
"enzyme-to-json": "^3.3.3",
"eslint": "^5.15.3",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-react": "^7.12.4",
"eslint": "^6.8.0",
"eslint-config-yoast": "file:packages/eslint",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-react": "^7.22.0",
"grunt-git": "^1.0.14",
"grunt-po2json": "^0.3.0",
"grunt-prompt": "^1.3.3",
Expand All @@ -92,12 +95,12 @@
"shusher": "^0.1.1",
"svg-react-loader": "^0.4.6",
"tmp": "^0.1.0",
"typescript": "^3.7.4",
"webpack": "^4.20.2",
"webpack-bundle-analyzer": "^3.0.2",
"webpack-cli": "^3.1.1",
"webpack-dev-server": "^3.1.14"
},
"dependencies": {},
"browserslist": [
"extends @yoast/browserslist-config"
],
Expand Down
2 changes: 1 addition & 1 deletion packages/browserslist-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
"scripts": {
"test": "jest",
"lint": "eslint .",
"lint": "eslint . --max-warnings=0",
"prepublishOnly": "rm -rf dist && cp -R src dist && cp package.json dist/package.json && json -I -f dist/package.json -e \\\"this.main='index.js'\\\""
},
"bugs": {
Expand Down
2 changes: 1 addition & 1 deletion packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"license": "GPL-3.0",
"scripts": {
"test": "jest",
"lint": "eslint . --max-warnings=96",
"lint": "eslint . --max-warnings=93",
"prepublishOnly": "rm -rf dist && cp -R src dist && cp package.json dist/package.json && json -I -f dist/package.json -e \"this.main='index.js'\" && cp .babelrc dist/.babelrc"
},
"jest": {
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/radiobutton/RadioButtonGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ const VerticalRadioButtons = ( { options, onChange, groupName, id, selected } )
id={ `${ id }_${ option.value }` }
{ ...option }
/>
</div>,
</div>
) }
</div>
);
Expand Down
4 changes: 2 additions & 2 deletions packages/components/tests/AlertTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe( "Alert", () => {
const component = renderer.create(
<Alert type={ alert.type }>
{ content }
</Alert>,
</Alert>
);
const tree = component.toJSON();

Expand Down Expand Up @@ -70,7 +70,7 @@ describe( "Alert", () => {
const component = renderer.create(
<Alert type="info" onDismissed={ dismiss }>
Dismissable alert.
</Alert>,
</Alert>
);
const tree = component.toJSON();

Expand Down
6 changes: 3 additions & 3 deletions packages/components/tests/CheckboxTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Checkbox from "../src/checkbox/Checkbox";
describe( "Checkbox", () => {
it( "matches the snapshot", () => {
const component = renderer.create(
<Checkbox id="test-id" label="test label" />,
<Checkbox id="test-id" label="test label" />
);

const tree = component.toJSON();
Expand All @@ -15,7 +15,7 @@ describe( "Checkbox", () => {

it( "matches the snapshot when an array is provided as a label", () => {
const component = renderer.create(
<Checkbox id="test-id" label={ [ "test label ", "using arrays" ] } />,
<Checkbox id="test-id" label={ [ "test label ", "using arrays" ] } />
);

const tree = component.toJSON();
Expand All @@ -34,7 +34,7 @@ describe( "Checkbox", () => {
id="testCallback"
onChange={ onChange }
label="testCallbackLabel"
/>,
/>
);

const tree = component.toTree();
Expand Down
2 changes: 1 addition & 1 deletion packages/components/tests/RadioButtonGroupTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe( "RadioButtonGroup", () => {
checked: true,
},
] }
/>,
/>
);

const result = renderer.getRenderOutput();
Expand Down
2 changes: 1 addition & 1 deletion packages/configuration-wizard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"private": false,
"scripts": {
"test": "jest",
"lint": "eslint . --max-warnings=11",
"lint": "eslint . --max-warnings=8",
"prepublishOnly": "rm -rf dist && cp -R src dist && cp package.json dist/package.json && json -I -f dist/package.json -e \"this.main='index.js'\" && mkdir dist/src && mkdir dist/src/helpers && cp src/helpers/_colors.scss dist/src/helpers/_colors.scss && cp .babelrc dist/.babelrc"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/feature-flag/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"private": false,
"scripts": {
"test": "jest --coverage",
"lint": "eslint ./src ./tests --max-warnings=5",
"lint": "eslint ./src ./tests --max-warnings=0",
"prepublishOnly": "rm -rf dist && cp -R src dist && cp package.json dist/package.json && json -I -f dist/package.json -e \"this.main='index.js'\""
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"scripts": {
"test": "jest",
"lint": "eslint .",
"lint": "eslint . --max-warnings=0",
"prepublishOnly": "rm -rf dist && cp -R src dist && cp package.json dist/package.json && json -I -f dist/package.json -e \"this.main='index.js'\" && cp .babelrc dist/.babelrc"
},
"author": "Yoast",
Expand Down
4 changes: 2 additions & 2 deletions packages/helpers/src/makeOutboundLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const makeOutboundLink = ( Component = "a" ) => {
{
target: "_blank",
rel: isYoastLink ? this.props.rel : "noopener",
},
}
);
// Use React.createElement instead of JSX because it can accept a string as a component parameter.
return React.createElement(
Expand All @@ -72,7 +72,7 @@ export const makeOutboundLink = ( Component = "a" ) => {
React.createElement(
A11yNotice,
null,
__( "(Opens in a new browser tab)", "yoast-components" ),
__( "(Opens in a new browser tab)", "yoast-components" )
)
);
}
Expand Down
Loading

0 comments on commit 2b2c5ab

Please sign in to comment.