Skip to content

Commit

Permalink
Packages: Reimplement ESLint config as plugin (#12763)
Browse files Browse the repository at this point in the history
* Packages: Move eslint-config to eslint-plugin

(Fails pre-commit, but in effort to ensure history preservation)

* eslint-plugin: Add npmrc to avoid package-lock.json

* Framework: Update path references for eslint-config to -plugin

* eslint-plugin: Reimplement ESLint config as plugin

* eslint-plugin: Unmark as private

* eslint-plugin: Undocument custom ruleset
  • Loading branch information
aduth authored and youknowriad committed Dec 12, 2018
1 parent 6c68815 commit 4dae3bc
Show file tree
Hide file tree
Showing 20 changed files with 206 additions and 277 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
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
Expand Up @@ -498,9 +498,9 @@
"parent": "packages"
},
{
"title": "@wordpress/eslint-config",
"slug": "packages-eslint-config",
"markdown_source": "https://raw.githubusercontent.com/WordPress/gutenberg/master/packages/eslint-config/README.md",
"title": "@wordpress/eslint-plugin",
"slug": "packages-eslint-plugin",
"markdown_source": "https://raw.githubusercontent.com/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
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
@@ -0,0 +1 @@
package-lock=false
48 changes: 48 additions & 0 deletions packages/eslint-plugin/README.md
@@ -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
@@ -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.',
},
],
},
};

0 comments on commit 4dae3bc

Please sign in to comment.