Skip to content

Commit

Permalink
Scripts: Add bare handling for lint-js script (no zero config)
Browse files Browse the repository at this point in the history
  • Loading branch information
gziolo committed Oct 11, 2018
1 parent f2da3e5 commit 085b66c
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 12 deletions.
40 changes: 35 additions & 5 deletions package-lock.json

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

7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@
"deasync": "0.1.13",
"deep-freeze": "0.0.1",
"doctrine": "2.1.0",
"eslint": "4.16.0",
"eslint-config-wordpress": "2.0.0",
"eslint-plugin-jest": "21.5.0",
"eslint-plugin-jsx-a11y": "6.0.2",
Expand Down Expand Up @@ -163,8 +162,8 @@
"fixtures:generate": "npm run fixtures:server-registered && cross-env GENERATE_MISSING_FIXTURES=y npm run test-unit",
"fixtures:regenerate": "npm run fixtures:clean && npm run fixtures:generate",
"lint": "concurrently \"npm run lint-js\" \"npm run lint-pkg-json\" \"npm run lint-css\"",
"lint-js": "eslint .",
"lint-js:fix": "eslint . --fix",
"lint-js": "wp-scripts lint-js .",
"lint-js:fix": "wp-scripts lint-js . --fix",
"lint-php": "docker-compose run --rm composer run-script lint",
"lint-pkg-json": "wp-scripts lint-pkg-json ./packages",
"lint-css": "stylelint '**/*.scss'",
Expand Down Expand Up @@ -201,7 +200,7 @@
"stylelint"
],
"*.js": [
"eslint"
"wp-scripts lint-js"
],
"{docs/{root-manifest.json,tool/*.js},packages/{*/README.md,*/src/{actions,selectors}.js,components/src/*/**/README.md}}": [
"npm run docs:build"
Expand Down
6 changes: 6 additions & 0 deletions packages/scripts/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 2.4.0 (Unreleased)

### New Feature

- Added support for `lint-js` script ([#10504](https://github.com/WordPress/gutenberg/pull/10504))

## 2.3.0 (2018-09-30)

### Improvements
Expand Down
21 changes: 19 additions & 2 deletions packages/scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,26 @@ _Example:_

## Available Scripts

### `wp-scripts lint-js`

Helps enforce coding style guidelines for your JavaScript files. It uses [eslint](https://eslint.org/) with no rules provided (we plan to add zero config support in the near future). You can specify your own rules as described in [eslint docs](https://eslint.org/docs/rules/).

_Example:_

```json
{
"scripts": {
"lint:js": "wp-scripts lint-js ."
}
}
```

This is how you execute the script with presented setup:
* `npm run lint:js` - lints JavaScripts files in the whole project's.

### `wp-scripts lint-pkg-json`

Helps enforce standards for your package.json file. It uses [npm-package-json-lint](https://www.npmjs.com/package/npm-package-json-lint) with the set of default rules provided. You can override them with your own rules as described in [npm-package-json-lint wiki](https://github.com/tclindner/npm-package-json-lint/wiki).
Helps enforce standards for your package.json files. It uses [npm-package-json-lint](https://www.npmjs.com/package/npm-package-json-lint) with the set of default rules provided. You can override them with your own rules as described in [npm-package-json-lint wiki](https://github.com/tclindner/npm-package-json-lint/wiki).

_Example:_

Expand All @@ -42,7 +59,7 @@ _Example:_
```

This is how you execute those scripts using the presented setup:
* `npm run lint:pkg-jsont` - lints `package.json` file in the project's root folder.
* `npm run lint:pkg-json` - lints `package.json` file in the project's root folder.

### `wp-scripts test-unit-js`

Expand Down
1 change: 1 addition & 0 deletions packages/scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"@wordpress/npm-package-json-lint-config": "file:../npm-package-json-lint-config",
"chalk": "^2.4.1",
"cross-spawn": "^5.1.0",
"eslint": "^4.19.1",
"jest": "^23.4.2",
"npm-package-json-lint": "^3.3.1",
"read-pkg-up": "^1.0.1",
Expand Down
33 changes: 33 additions & 0 deletions packages/scripts/scripts/lint-js.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* External dependencies
*/
const { sync: spawn } = require( 'cross-spawn' );
const { sync: resolveBin } = require( 'resolve-bin' );

/**
* Internal dependencies
*/
const {
fromConfigRoot,
getCliArgs,
hasCliArg,
hasProjectFile,
} = require( '../utils' );

const args = getCliArgs();

const hasLintConfig = hasCliArg( '-c' ) ||
hasCliArg( '--configFile' ) ||
hasProjectFile( '.eslintrc.js' );

const config = ! hasLintConfig ?
[ '--configFile', fromConfigRoot( '.eslintrc.js' ) ] :
[];

const result = spawn(
resolveBin( 'eslint' ),
[ ...config, ...args ],
{ stdio: 'inherit' }
);

process.exit( result.status );
2 changes: 1 addition & 1 deletion test/e2e/specs/preview.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe( 'Preview', () => {

// When autosave completes for a new post, the URL of the editor should
// update to include the ID. Use this to assert on preview URL.
const [ , postId ] = await ( await editorPage.waitForFunction( () => {
const [ , postId ] = await( await editorPage.waitForFunction( () => {
return window.location.search.match( /[\?&]post=(\d+)/ );
} ) ).jsonValue();

Expand Down

0 comments on commit 085b66c

Please sign in to comment.