Skip to content

Commit

Permalink
Scripts: Ignore linting files located in build folders by default (#1…
Browse files Browse the repository at this point in the history
…5977)

* Scripts: Ignore linting files located in build folders by default

* Add CHANGELOG entry
  • Loading branch information
gziolo committed Jun 5, 2019
1 parent 672599a commit c85e28f
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 5 deletions.
6 changes: 6 additions & 0 deletions packages/scripts/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## Master

### New Features

- The `lint-js`, `lint-pkg-json` and `lint-style` commands ignore now files located in `build` and `node_modules` folders by default ([15977](https://github.com/WordPress/gutenberg/pull/15977)).

## 3.2.0 (2019-05-21)

### New Feature
Expand Down
7 changes: 7 additions & 0 deletions packages/scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ This is how you execute the script with presented setup:

* `npm run lint:js` - lints JavaScript files in the entire project's directories.


By default, files located in `build` and `node_modules` folders are ignored.

#### Advanced information

It uses [eslint](https://eslint.org/) with the set of recommended rules defined in [@wordpress/eslint-plugin](https://www.npmjs.com/package/@wordpress/eslint-plugin) npm package. You can override default rules with your own as described in [eslint docs](https://eslint.org/docs/rules/). Learn more in the [Advanced Usage](#advanced-usage) section.
Expand All @@ -145,6 +148,8 @@ This is how you execute those scripts using the presented setup:

* `npm run lint:pkg-json` - lints `package.json` file in the project's root folder.

By default, files located in `build` and `node_modules` folders are ignored.

#### Advanced information

It uses [npm-package-json-lint](https://www.npmjs.com/package/npm-package-json-lint) with the set of recommended rules defined in [@wordpress/npm-package-json-lint-config](https://www.npmjs.com/package/@wordpress/npm-package-json-lint-config) npm package. You can override default rules with your own as described in [npm-package-json-lint wiki](https://github.com/tclindner/npm-package-json-lint/wiki). Learn more in the [Advanced Usage](#advanced-usage) section.
Expand All @@ -167,6 +172,8 @@ This is how you execute the script with presented setup:

* `npm run lint:css` - lints CSS files in the whole project's directory.

By default, files located in `build` and `node_modules` folders are ignored.

#### Advanced information

It uses [stylelint](https://github.com/stylelint/stylelint) with the [stylelint-config-wordpress](https://github.com/WordPress-Coding-Standards/stylelint-config-wordpress) configuration per the [WordPress CSS Coding Standards](https://make.wordpress.org/core/handbook/best-practices/coding-standards/css/). You can override them with your own rules as described in [stylelint user guide](https://github.com/stylelint/stylelint/docs/user-guide.md). Learn more in the [Advanced Usage](#advanced-usage) section.
Expand Down
2 changes: 2 additions & 0 deletions packages/scripts/config/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build
node_modules
3 changes: 3 additions & 0 deletions packages/scripts/config/.npmpackagejsonlintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# By default, all `node_modules` are ignored.

build
3 changes: 3 additions & 0 deletions packages/scripts/config/.stylelintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# By default, all `node_modules` are ignored.

build
11 changes: 10 additions & 1 deletion packages/scripts/scripts/lint-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const {

const args = getCliArgs();

// See: https://eslint.org/docs/user-guide/configuring#using-configuration-files-1.
const hasLintConfig = hasCliArg( '-c' ) ||
hasCliArg( '--config' ) ||
hasProjectFile( '.eslintrc.js' ) ||
Expand All @@ -33,9 +34,17 @@ const config = ! hasLintConfig ?
[ '--no-eslintrc', '--config', fromConfigRoot( '.eslintrc.js' ) ] :
[];

// See: https://eslint.org/docs/user-guide/configuring#ignoring-files-and-directories.
const hasIgnoredFiles = hasCliArg( '--ignore-path' ) ||
hasProjectFile( '.eslintignore' );

const defaultIgnoreArgs = ! hasIgnoredFiles ?
[ '--ignore-path', fromConfigRoot( '.eslintignore' ) ] :
[];

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

Expand Down
11 changes: 10 additions & 1 deletion packages/scripts/scripts/lint-pkg-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const {

const args = getCliArgs();

// See: https://github.com/tclindner/npm-package-json-lint/wiki/configuration#configuration.
const hasLintConfig = hasCliArg( '-c' ) ||
hasCliArg( '--configFile' ) ||
hasProjectFile( '.npmpackagejsonlintrc.json' ) ||
Expand All @@ -27,9 +28,17 @@ const config = ! hasLintConfig ?
[ '--configFile', fromConfigRoot( 'npmpackagejsonlint.json' ) ] :
[];

// See: https://github.com/tclindner/npm-package-json-lint/#cli-commands-and-configuration.
const hasIgnoredFiles = hasCliArg( '--ignorePath' ) ||
hasProjectFile( '.npmpackagejsonlintignore' );

const defaultIgnoreArgs = ! hasIgnoredFiles ?
[ '--ignorePath', fromConfigRoot( '.npmpackagejsonlintignore' ) ] :
[];

const result = spawn(
resolveBin( 'npm-package-json-lint', { executable: 'npmPkgJsonLint' } ),
[ ...config, ...args ],
[ ...config, ...defaultIgnoreArgs, ...args ],
{ stdio: 'inherit' }
);

Expand Down
15 changes: 12 additions & 3 deletions packages/scripts/scripts/lint-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const {

const args = getCliArgs();

const hasStylelintConfig = hasCliArg( '--config' ) ||
// See: https://github.com/stylelint/stylelint/blob/master/docs/user-guide/configuration.md#loading-the-configuration-object.
const hasLintConfig = hasCliArg( '--config' ) ||
hasProjectFile( '.stylelintrc' ) ||
hasProjectFile( '.stylelintrc.js' ) ||
hasProjectFile( '.stylelintrc.json' ) ||
Expand All @@ -26,13 +27,21 @@ const hasStylelintConfig = hasCliArg( '--config' ) ||
hasProjectFile( '.stylelint.config.js' ) ||
hasPackageProp( 'stylelint' );

const config = ! hasStylelintConfig ?
const config = ! hasLintConfig ?
[ '--config', fromConfigRoot( '.stylelintrc.json' ) ] :
[];

// See: https://github.com/stylelint/stylelint/blob/master/docs/user-guide/configuration.md#stylelintignore.
const hasIgnoredFiles = hasCliArg( '--ignore-path' ) ||
hasProjectFile( '.stylelintignore' );

const defaultIgnoreArgs = ! hasIgnoredFiles ?
[ '--ignore-path', fromConfigRoot( '.stylelintignore' ) ] :
[];

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

Expand Down

0 comments on commit c85e28f

Please sign in to comment.