From 949389733229d837844b21608607b2b1c90c5eec Mon Sep 17 00:00:00 2001 From: Grzegorz Ziolkowski Date: Wed, 29 May 2019 16:35:02 +0200 Subject: [PATCH] Scripts: Add default file patterns for linting scripts --- package-lock.json | 123 ++++------------------ package.json | 10 +- packages/scripts/README.md | 32 ++++-- packages/scripts/package.json | 1 + packages/scripts/scripts/lint-js.js | 7 +- packages/scripts/scripts/lint-pkg-json.js | 7 +- packages/scripts/scripts/lint-style.js | 7 +- packages/scripts/utils/cli.js | 4 + packages/scripts/utils/index.js | 4 +- 9 files changed, 73 insertions(+), 122 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0ad2380805580..18ac2f11af77b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -53,12 +53,6 @@ "minimist": "^1.2.0" } }, - "minimist": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", - "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", - "dev": true - }, "ms": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz", @@ -937,14 +931,6 @@ "requires": { "exec-sh": "^0.3.2", "minimist": "^1.2.0" - }, - "dependencies": { - "minimist": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", - "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", - "dev": true - } } }, "@iarna/toml": { @@ -3812,6 +3798,7 @@ "eslint": "^5.16.0", "jest": "^24.7.1", "jest-puppeteer": "^4.0.0", + "minimist": "^1.2.0", "npm-package-json-lint": "^3.6.0", "puppeteer": "1.6.1", "read-pkg-up": "^1.0.1", @@ -5466,12 +5453,6 @@ "semver": "^5.0.3" }, "dependencies": { - "minimist": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", - "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", - "dev": true - }, "semver": { "version": "5.7.0", "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.0.tgz", @@ -5923,7 +5904,8 @@ "dependencies": { "minimist": { "version": "1.2.0", - "bundled": true, + "resolved": false, + "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", "dev": true, "optional": true } @@ -6814,12 +6796,6 @@ "trim-newlines": "^2.0.0" } }, - "minimist": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", - "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", - "dev": true - }, "parse-json": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-4.0.0.tgz", @@ -6928,12 +6904,6 @@ "trim-newlines": "^2.0.0" } }, - "minimist": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", - "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", - "dev": true - }, "parse-json": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-4.0.0.tgz", @@ -7045,12 +7015,6 @@ "trim-newlines": "^2.0.0" } }, - "minimist": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", - "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", - "dev": true - }, "parse-json": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-4.0.0.tgz", @@ -10194,7 +10158,8 @@ "dependencies": { "minimist": { "version": "1.2.0", - "bundled": true, + "resolved": false, + "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", "dev": true, "optional": true } @@ -10524,12 +10489,6 @@ "trim-newlines": "^1.0.0" } }, - "minimist": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", - "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", - "dev": true - }, "redent": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/redent/-/redent-1.0.0.tgz", @@ -10640,12 +10599,6 @@ "trim-newlines": "^2.0.0" } }, - "minimist": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", - "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", - "dev": true - }, "parse-json": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-4.0.0.tgz", @@ -10740,12 +10693,6 @@ "trim-newlines": "^2.0.0" } }, - "minimist": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", - "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", - "dev": true - }, "parse-json": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-4.0.0.tgz", @@ -14804,9 +14751,9 @@ } }, "minimist": { - "version": "0.0.8", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", - "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", + "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", "dev": true }, "minimist-options": { @@ -14910,6 +14857,14 @@ "dev": true, "requires": { "minimist": "0.0.8" + }, + "dependencies": { + "minimist": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", + "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", + "dev": true + } } }, "modify-values": { @@ -15369,12 +15324,6 @@ "mime-db": "1.40.0" } }, - "minimist": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", - "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", - "dev": true - }, "nan": { "version": "2.13.2", "resolved": "https://registry.npmjs.org/nan/-/nan-2.13.2.tgz", @@ -16025,6 +15974,12 @@ "wordwrap": "~0.0.2" }, "dependencies": { + "minimist": { + "version": "0.0.10", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.10.tgz", + "integrity": "sha1-3j+YVD2/lggr5IrRoMfNqDYwHc8=", + "dev": true + }, "wordwrap": { "version": "0.0.3", "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.3.tgz", @@ -16684,12 +16639,6 @@ "minimist": "^1.2.0" } }, - "minimist": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", - "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", - "dev": true - }, "ms": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz", @@ -17446,12 +17395,6 @@ "minimist": "^1.2.0" } }, - "minimist": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", - "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", - "dev": true - }, "ms": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz", @@ -18256,14 +18199,6 @@ "buffer-equal": "0.0.1", "minimist": "^1.1.3", "through2": "^2.0.0" - }, - "dependencies": { - "minimist": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", - "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", - "dev": true - } } }, "raf": { @@ -19412,12 +19347,6 @@ "pump": "^3.0.0" } }, - "minimist": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", - "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", - "dev": true - }, "pump": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz", @@ -20532,14 +20461,6 @@ "duplexer": "^0.1.1", "minimist": "^1.2.0", "through": "^2.3.4" - }, - "dependencies": { - "minimist": { - "version": "1.2.0", - "resolved": "http://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", - "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", - "dev": true - } } }, "style-search": { diff --git a/package.json b/package.json index 527d358b982b3..28023f23fd345 100644 --- a/package.json +++ b/package.json @@ -2,14 +2,18 @@ "name": "gutenberg", "version": "5.8.0", "private": true, - "description": "A new WordPress editor experience", - "repository": "git+https://github.com/WordPress/gutenberg.git", + "description": "A new WordPress editor experience.", "author": "The WordPress Contributors", "license": "GPL-2.0-or-later", "keywords": [ "WordPress", "editor" ], + "homepage": "https://github.com/WordPress/gutenberg/", + "repository": "git+https://github.com/WordPress/gutenberg.git", + "bugs": { + "url": "https://github.com/WordPress/gutenberg/issues" + }, "config": { "GUTENBERG_PHASE": 2 }, @@ -177,7 +181,7 @@ "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": "wp-scripts lint-js .", + "lint-js": "wp-scripts lint-js", "lint-js:fix": "npm run lint-js -- --fix", "lint-php": "docker-compose run --rm composer run-script lint", "lint-pkg-json": "wp-scripts lint-pkg-json ./packages", diff --git a/packages/scripts/README.md b/packages/scripts/README.md index b21c7078a61d5..a99d2ed0d0ec3 100644 --- a/packages/scripts/README.md +++ b/packages/scripts/README.md @@ -25,10 +25,10 @@ _Example:_ "scripts": { "build": "wp-scripts build", "check-engines": "wp-scripts check-engines", - "check-licenses": "wp-scripts check-licenses --production", - "lint:css": "wp-scripts lint-style '**/*.css'", - "lint:js": "wp-scripts lint-js .", - "lint:pkg-json": "wp-scripts lint-pkg-json .", + "check-licenses": "wp-scripts check-licenses", + "lint:css": "wp-scripts lint-style", + "lint:js": "wp-scripts lint-js", + "lint:pkg-json": "wp-scripts lint-pkg-json", "start": "wp-scripts start", "test:e2e": "wp-scripts test-e2e", "test:unit": "wp-scripts test-unit-js" @@ -101,7 +101,7 @@ _Example:_ _Flags_: - `--prod` (or `--production`): When present, validates only `dependencies` and not `devDependencies` -- `--dev` (or `--development`): When present, validates both `dependencies` and `devDependencies` +- `--dev` (or `--development`): When present, validates only `devDependencies` and not `dependencies` - `--gpl2`: Validates against [GPLv2 license compatibility](https://www.gnu.org/licenses/license-list.en.html) - `--ignore=a,b,c`: A comma-separated set of package names to ignore for validation. This is intended to be used primarily in cases where a dependency's `license` field is malformed. It's assumed that any `ignored` package argument would be manually vetted for compatibility by the project owner. @@ -114,7 +114,8 @@ _Example:_ ```json { "scripts": { - "lint:js": "wp-scripts lint-js ." + "lint:js": "wp-scripts lint-js", + "lint:js:src": "wp-scripts lint-js ./src" } } ``` @@ -122,6 +123,9 @@ _Example:_ This is how you execute the script with presented setup: * `npm run lint:js` - lints JavaScript files in the entire project's directories. +* `npm run lint:js:src` - lints JavaScript files in the project's `src` subfolder's directories. + +When you run commands similar to the `npm run lint:js:src` example above, you can provide a file, a directory, or `glob` syntax or any combination of them. See [more examples](https://eslint.org/docs/user-guide/command-line-interface). #### Advanced information @@ -136,14 +140,18 @@ _Example:_ ```json { "scripts": { - "lint:pkg-json": "wp-scripts lint-pkg-json ." + "lint:pkg-json": "wp-scripts lint-pkg-json", + "lint:pkg-json:src": "wp-scripts lint-pkg-json ./src" } } ``` 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. +* `npm run lint:pkg-json` - lints `package.json` file in the entire project's directories. +* `npm run lint:pkg-json:src` - lints `package.json` file in the project's `src` subfolder's directories. + +When you run commands similar to the `npm run lint:pkg-json:src` example above, you can provide one or multiple directories to scan as well. See [more examples](https://github.com/tclindner/npm-package-json-lint/blob/HEAD/README.md#examples). #### Advanced information @@ -158,14 +166,18 @@ _Example:_ ```json { "scripts": { - "lint:css": "wp-scripts lint-style '**/*.css'" + "lint:style": "wp-scripts lint-style", + "lint:css:src": "wp-scripts lint-style 'src/**/*.css'" } } ``` This is how you execute the script with presented setup: -* `npm run lint:css` - lints CSS files in the whole project's directory. +* `npm run lint:style` - lints CSS and SCSS files in the entire project's directories. +* `npm run lint:css:src` - lints only CSS files in the project's `src` subfolder's directories. + +When you run commands similar to the `npm run lint:css:src` example above, be sure to include the quotation marks around file globs. This ensures that you can use the powers of [globby](https://github.com/sindresorhus/globby) (like the `**` globstar) regardless of your shell. See [more examples](https://github.com/stylelint/stylelint/blob/HEAD/docs/user-guide/cli.md#examples). #### Advanced information diff --git a/packages/scripts/package.json b/packages/scripts/package.json index 712b5edde2b3f..c8d503efb886c 100644 --- a/packages/scripts/package.json +++ b/packages/scripts/package.json @@ -44,6 +44,7 @@ "eslint": "^5.16.0", "jest": "^24.7.1", "jest-puppeteer": "^4.0.0", + "minimist": "^1.2.0", "npm-package-json-lint": "^3.6.0", "puppeteer": "1.6.1", "read-pkg-up": "^1.0.1", diff --git a/packages/scripts/scripts/lint-js.js b/packages/scripts/scripts/lint-js.js index c7346fb76ad88..d8f4a1345bc6d 100644 --- a/packages/scripts/scripts/lint-js.js +++ b/packages/scripts/scripts/lint-js.js @@ -11,12 +11,15 @@ const { fromConfigRoot, getCliArgs, hasCliArg, + hasFileInCliArgs, hasPackageProp, hasProjectFile, } = require( '../utils' ); const args = getCliArgs(); +const defaultFilesArgs = ! hasFileInCliArgs ? [ '.' ] : []; + const hasLintConfig = hasCliArg( '-c' ) || hasCliArg( '--config' ) || hasProjectFile( '.eslintrc.js' ) || @@ -29,13 +32,13 @@ const hasLintConfig = hasCliArg( '-c' ) || // When a configuration is not provided by the project, use from the default // provided with the scripts module. Instruct ESLint to avoid discovering via // the `--no-eslintrc` flag, as otherwise it will still merge with inherited. -const config = ! hasLintConfig ? +const defaultConfigArgs = ! hasLintConfig ? [ '--no-eslintrc', '--config', fromConfigRoot( '.eslintrc.js' ) ] : []; const result = spawn( resolveBin( 'eslint' ), - [ ...config, ...args ], + [ ...defaultConfigArgs, ...args, ...defaultFilesArgs ], { stdio: 'inherit' } ); diff --git a/packages/scripts/scripts/lint-pkg-json.js b/packages/scripts/scripts/lint-pkg-json.js index b37e0a07bc75b..2df1f5f854c76 100644 --- a/packages/scripts/scripts/lint-pkg-json.js +++ b/packages/scripts/scripts/lint-pkg-json.js @@ -11,25 +11,28 @@ const { fromConfigRoot, getCliArgs, hasCliArg, + hasFileInCliArgs, hasProjectFile, hasPackageProp, } = require( '../utils' ); const args = getCliArgs(); +const defaultFilesArgs = ! hasFileInCliArgs ? [ '.' ] : []; + const hasLintConfig = hasCliArg( '-c' ) || hasCliArg( '--configFile' ) || hasProjectFile( '.npmpackagejsonlintrc.json' ) || hasProjectFile( 'npmpackagejsonlint.config.js' ) || hasPackageProp( 'npmPackageJsonLintConfig' ); -const config = ! hasLintConfig ? +const defaultConfigArgs = ! hasLintConfig ? [ '--configFile', fromConfigRoot( 'npmpackagejsonlint.json' ) ] : []; const result = spawn( resolveBin( 'npm-package-json-lint', { executable: 'npmPkgJsonLint' } ), - [ ...config, ...args ], + [ ...defaultConfigArgs, ...args, defaultFilesArgs ], { stdio: 'inherit' } ); diff --git a/packages/scripts/scripts/lint-style.js b/packages/scripts/scripts/lint-style.js index d72a877fa9370..297d805a736bf 100644 --- a/packages/scripts/scripts/lint-style.js +++ b/packages/scripts/scripts/lint-style.js @@ -11,12 +11,15 @@ const { fromConfigRoot, getCliArgs, hasCliArg, + hasFileInCliArgs, hasProjectFile, hasPackageProp, } = require( '../utils' ); const args = getCliArgs(); +const defaultFilesArgs = ! hasFileInCliArgs ? [ '**/*.{css,scss}' ] : []; + const hasStylelintConfig = hasCliArg( '--config' ) || hasProjectFile( '.stylelintrc' ) || hasProjectFile( '.stylelintrc.js' ) || @@ -26,13 +29,13 @@ const hasStylelintConfig = hasCliArg( '--config' ) || hasProjectFile( '.stylelint.config.js' ) || hasPackageProp( 'stylelint' ); -const config = ! hasStylelintConfig ? +const defaultConfigArgs = ! hasStylelintConfig ? [ '--config', fromConfigRoot( '.stylelintrc.json' ) ] : []; const result = spawn( resolveBin( 'stylelint' ), - [ ...config, ...args ], + [ ...defaultConfigArgs, ...args, ...defaultFilesArgs ], { stdio: 'inherit' } ); diff --git a/packages/scripts/utils/cli.js b/packages/scripts/utils/cli.js index 3778379ced192..db4ce5fcef2d4 100644 --- a/packages/scripts/utils/cli.js +++ b/packages/scripts/utils/cli.js @@ -1,6 +1,7 @@ /** * External dependencies */ +const minimist = require( 'minimist' ); const spawn = require( 'cross-spawn' ); /** @@ -26,6 +27,8 @@ const getCliArg = ( arg ) => { const hasCliArg = ( arg ) => getCliArg( arg ) !== undefined; +const hasFileInCliArgs = () => minimist( getCliArgs() )._.length > 0; + const handleSignal = ( signal ) => { if ( signal === 'SIGKILL' ) { // eslint-disable-next-line no-console @@ -81,5 +84,6 @@ module.exports = { getCliArg, getCliArgs, hasCliArg, + hasFileInCliArgs, spawnScript, }; diff --git a/packages/scripts/utils/index.js b/packages/scripts/utils/index.js index aebbcdca71800..2912c9aee22bb 100644 --- a/packages/scripts/utils/index.js +++ b/packages/scripts/utils/index.js @@ -5,8 +5,8 @@ const { getCliArg, getCliArgs, hasCliArg, + hasFileInCliArgs, spawnScript, - cleanUpArgs, } = require( './cli' ); const { getWebpackArgs, @@ -32,9 +32,9 @@ module.exports = { getWebpackArgs, hasBabelConfig, hasCliArg, + hasFileInCliArgs, hasJestConfig, hasPackageProp, hasProjectFile, spawnScript, - cleanUpArgs, };