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

Scripts: Ignore linting files located in build folders by default #15977

Merged
merged 2 commits into from
Jun 5, 2019
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
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