Skip to content

Commit

Permalink
Packages: Extract Eslint config package (#7965)
Browse files Browse the repository at this point in the history
* Packages: Extract Eslint config package

* Copy config from eslint-config-wordpress

* Docs: Expose documentation for the newly added package

* Remove no longer necessary globals from the Eslint config

* Apply suggestions from code review

Fix ESLint typo
Kudos to @ntwb for catching

Co-Authored-By: gziolo <[email protected]>
  • Loading branch information
gziolo authored Nov 30, 2018
1 parent 05e5ea8 commit d4d3e0c
Show file tree
Hide file tree
Showing 13 changed files with 286 additions and 122 deletions.
16 changes: 7 additions & 9 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,8 @@ const majorMinorRegExp = escapeRegExp( version.replace( /\.\d+$/, '' ) ) + '(\\.
module.exports = {
root: true,
extends: [
'./eslint/config.js',
'plugin:jest/recommended'
],
env: {
'jest/globals': true,
},
plugins: [
'jest',
'@wordpress/eslint-config',
'plugin:jest/recommended',
],
rules: {
'no-restricted-syntax': [
Expand Down Expand Up @@ -189,9 +183,13 @@ module.exports = {
overrides: [
{
files: [ 'test/e2e/**/*.js' ],
env: {
browser: true,
},
globals: {
page: true,
browser: true,
page: true,
wp: true,
},
},
],
Expand Down
6 changes: 6 additions & 0 deletions docs/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,12 @@
"markdown_source": "https://raw.githubusercontent.com/WordPress/gutenberg/master/packages/escape-html/README.md",
"parent": "packages"
},
{
"title": "@wordpress/eslint-config",
"slug": "packages-eslint-config",
"markdown_source": "https://raw.githubusercontent.com/WordPress/gutenberg/master/packages/eslint-config/README.md",
"parent": "packages"
},
{
"title": "@wordpress/format-library",
"slug": "packages-format-library",
Expand Down
145 changes: 43 additions & 102 deletions package-lock.json

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

5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,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/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 All @@ -80,11 +81,7 @@
"deasync": "0.1.13",
"deep-freeze": "0.0.1",
"doctrine": "2.1.0",
"eslint-config-wordpress": "2.0.0",
"eslint-plugin-jest": "21.5.0",
"eslint-plugin-jsx-a11y": "6.0.2",
"eslint-plugin-react": "7.7.0",
"eslint-plugin-wordpress": "git://github.com/WordPress-Coding-Standards/eslint-plugin-wordpress.git#1774343f6226052a46b081e01db3fca8793cc9f1",
"espree": "3.5.4",
"glob": "7.1.2",
"husky": "0.14.3",
Expand Down
2 changes: 2 additions & 0 deletions packages/block-library/src/classic/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { Component } from '@wordpress/element';
import { __, _x } from '@wordpress/i18n';
import { BACKSPACE, DELETE, F10 } from '@wordpress/keycodes';

const { wp } = window;

function isTmceEmpty( editor ) {
// When tinyMce is empty the content seems to be:
// <p><br data-mce-bogus="1"></p>
Expand Down
6 changes: 4 additions & 2 deletions packages/edit-post/src/hooks/components/media-upload/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
/**
* External Dependencies
*/
import { castArray, pick } from 'lodash';
import { castArray, defaults, pick } from 'lodash';

/**
* WordPress dependencies
*/
import { Component } from '@wordpress/element';
import { __ } from '@wordpress/i18n';

const { wp } = window;

// Getter for the sake of unit tests.
const getGalleryDetailsMediaFrame = () => {
/**
Expand Down Expand Up @@ -36,7 +38,7 @@ const getGalleryDetailsMediaFrame = () => {
multiple: 'add',
editable: false,

library: wp.media.query( _.defaults( {
library: wp.media.query( defaults( {
type: 'image',
}, this.options.library ) ),
} ),
Expand Down
24 changes: 24 additions & 0 deletions packages/eslint-config/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# ESLint Config

[ESLint](https://eslint.org/) config for WordPress development.

## Installation

Install the module

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

### Usage

Next, extend the configuration from your project's `.eslintrc` file:

```json
"extends": "@wordpress/eslint-config"
```

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


<br/><br/><p align="center"><img src="https://s.w.org/style/images/codeispoetry.png?1" alt="Code is Poetry." /></p>
12 changes: 12 additions & 0 deletions packages/eslint-config/configs/es5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* The original version of this file is based on WordPress ESLint rules and shared configs:
* https://github.com/WordPress-Coding-Standards/eslint-plugin-wordpress.
*/

module.exports = {
env: {
es6: true,
},

rules: require( './rules/esnext' ),
};
8 changes: 8 additions & 0 deletions packages/eslint-config/configs/esnext.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* The original version of this file is based on WordPress ESLint rules and shared configs:
* https://github.com/WordPress-Coding-Standards/eslint-plugin-wordpress.
*/

module.exports = {
rules: require( './rules/es5' ),
};
Loading

0 comments on commit d4d3e0c

Please sign in to comment.