From 36fd62b9b7ca3cfa54bbbee7e377a95a79b47974 Mon Sep 17 00:00:00 2001 From: Marcus Kazmierczak Date: Thu, 23 Jan 2020 16:26:13 -0800 Subject: [PATCH 01/10] Add markdownlint script to lint docs markup Adds a new script `lint-md-docs` that runs markdownlint to lint markdown files for proper syntax. A default `.markdownlint.json` config is included, it will require some testing to tune. Fixes #12426 --- .markdownlintignore | 9 ++ package-lock.json | 131 ++++++++++++++++++++- package.json | 1 + packages/scripts/config/.markdownlint.json | 8 ++ packages/scripts/package.json | 2 + packages/scripts/scripts/lint-md-docs.js | 46 ++++++++ 6 files changed, 195 insertions(+), 2 deletions(-) create mode 100644 .markdownlintignore create mode 100644 packages/scripts/config/.markdownlint.json create mode 100644 packages/scripts/scripts/lint-md-docs.js diff --git a/.markdownlintignore b/.markdownlintignore new file mode 100644 index 0000000000000..8ea95a227e974 --- /dev/null +++ b/.markdownlintignore @@ -0,0 +1,9 @@ +bin +build +node_modules +phpunit +playground +storybook +test +vendor +wordpress diff --git a/package-lock.json b/package-lock.json index 1c409785d2cf2..1781227b53582 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10770,6 +10770,8 @@ "jest-puppeteer": "^4.3.0", "js-yaml": "^3.13.1", "lodash": "^4.17.15", + "markdownlint": "^0.18.0", + "markdownlint-cli": "^0.21.0", "minimist": "^1.2.0", "npm-package-json-lint": "^4.0.3", "prettier": "npm:wp-prettier@1.19.1", @@ -20835,6 +20837,12 @@ "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.11.tgz", "integrity": "sha1-Dovf5NHduIVNZOBOp8AOKgJuVlg=" }, + "graceful-readlink": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/graceful-readlink/-/graceful-readlink-1.0.1.tgz", + "integrity": "sha1-TK+tdrxi8C+gObL5Tpo906ORpyU=", + "dev": true + }, "gradient-parser": { "version": "0.1.5", "resolved": "https://registry.npmjs.org/gradient-parser/-/gradient-parser-0.1.5.tgz", @@ -26166,6 +26174,12 @@ "integrity": "sha1-Hq3nrMASA0rYTiOWdn6tn6VJWCE=", "dev": true }, + "jsonc-parser": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/jsonc-parser/-/jsonc-parser-2.2.0.tgz", + "integrity": "sha512-4fLQxW1j/5fWj6p78vAlAafoCKtuBm6ghv+Ij5W2DrDx0qE+ZdEl2c6Ko1mgJNF5ftX1iEWQQ4Ap7+3GlhjkOA==", + "dev": true + }, "jsonfile": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz", @@ -26358,6 +26372,15 @@ "resolved": "https://registry.npmjs.org/lines-and-columns/-/lines-and-columns-1.1.6.tgz", "integrity": "sha1-HADHQ7QzzQpOgHWPe2SldEDZ/wA=" }, + "linkify-it": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-2.2.0.tgz", + "integrity": "sha512-GnAl/knGn+i1U/wjBz3akz2stz+HrHLsxMwHQGofCDfPvlf+gDKN58UtfmUquTY4/MXeE2x7k19KQmeoZi94Iw==", + "dev": true, + "requires": { + "uc.micro": "^1.0.1" + } + }, "lint-staged": { "version": "9.2.5", "resolved": "https://registry.npmjs.org/lint-staged/-/lint-staged-9.2.5.tgz", @@ -26800,6 +26823,12 @@ "integrity": "sha1-gteb/zCmfEAF/9XiUVMArZyk168=", "dev": true }, + "lodash.differencewith": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/lodash.differencewith/-/lodash.differencewith-4.5.0.tgz", + "integrity": "sha1-uvr7yRi1UVTheRdqALsK76rIVLc=", + "dev": true + }, "lodash.escape": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/lodash.escape/-/lodash.escape-4.0.1.tgz", @@ -26812,6 +26841,12 @@ "integrity": "sha1-ZosdSYFgOuHMWm+nYBQ+SAtMSs4=", "dev": true }, + "lodash.flatten": { + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/lodash.flatten/-/lodash.flatten-4.4.0.tgz", + "integrity": "sha1-8xwiIlqWMtK7+OSt2+8kCqdlph8=", + "dev": true + }, "lodash.flattendeep": { "version": "4.4.0", "resolved": "https://registry.npmjs.org/lodash.flattendeep/-/lodash.flattendeep-4.4.0.tgz", @@ -27441,6 +27476,27 @@ "integrity": "sha512-lbRZ2mE3Q9RtLjxZBZ9+IMl68DKIXaVAhwvwn9pmjnPLS0h/6kyBMgNhqi1xFJ/2yv6cSyv0jbiZavZv93JkkA==", "dev": true }, + "markdown-it": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-10.0.0.tgz", + "integrity": "sha512-YWOP1j7UbDNz+TumYP1kpwnP0aEa711cJjrAQrzd0UXlbJfc5aAq0F/PZHjiioqDC1NKgvIMX+o+9Bk7yuM2dg==", + "dev": true, + "requires": { + "argparse": "^1.0.7", + "entities": "~2.0.0", + "linkify-it": "^2.0.0", + "mdurl": "^1.0.1", + "uc.micro": "^1.0.5" + }, + "dependencies": { + "entities": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/entities/-/entities-2.0.0.tgz", + "integrity": "sha512-D9f7V0JSRwIxlRI2mjMqufDrRDnx8p+eEOz7aUM9SuvF8gsBzra0/6tbjl1m8eQHrZlYj6PxqE00hZ1SAIKPLw==", + "dev": true + } + } + }, "markdown-table": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/markdown-table/-/markdown-table-1.1.2.tgz", @@ -27457,6 +27513,71 @@ "unquote": "^1.1.0" } }, + "markdownlint": { + "version": "0.18.0", + "resolved": "https://registry.npmjs.org/markdownlint/-/markdownlint-0.18.0.tgz", + "integrity": "sha512-nQAfK9Pbq0ZRoMC/abNGterEnV3kL8MZmi0WHhw8WJKoIbsm3cXGufGsxzCRvjW15cxe74KWcxRSKqwplS26Bw==", + "dev": true, + "requires": { + "markdown-it": "10.0.0" + } + }, + "markdownlint-cli": { + "version": "0.21.0", + "resolved": "https://registry.npmjs.org/markdownlint-cli/-/markdownlint-cli-0.21.0.tgz", + "integrity": "sha512-gvnczz3W3Wgex851/cIQ/2y8GNhY+EVK8Ael8kRd8hoSQ0ps9xjhtwPwMyJPoiYbAoPxG6vSBFISiysaAbCEZg==", + "dev": true, + "requires": { + "commander": "~2.9.0", + "deep-extend": "~0.5.1", + "get-stdin": "~5.0.1", + "glob": "~7.1.2", + "ignore": "~5.1.4", + "js-yaml": "~3.13.1", + "jsonc-parser": "~2.2.0", + "lodash.differencewith": "~4.5.0", + "lodash.flatten": "~4.4.0", + "markdownlint": "~0.18.0", + "markdownlint-rule-helpers": "~0.6.0", + "minimatch": "~3.0.4", + "rc": "~1.2.7" + }, + "dependencies": { + "commander": { + "version": "2.9.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.9.0.tgz", + "integrity": "sha1-nJkJQXbhIkDLItbFFGCYQA/g99Q=", + "dev": true, + "requires": { + "graceful-readlink": ">= 1.0.0" + } + }, + "deep-extend": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.5.1.tgz", + "integrity": "sha512-N8vBdOa+DF7zkRrDCsaOXoCs/E2fJfx9B9MrKnnSiHNh4ws7eSys6YQE4KvT1cecKmOASYQBhbKjeuDD9lT81w==", + "dev": true + }, + "get-stdin": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-5.0.1.tgz", + "integrity": "sha1-Ei4WFZHiH/TFJTAwVpPyDmOTo5g=", + "dev": true + }, + "ignore": { + "version": "5.1.4", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.1.4.tgz", + "integrity": "sha512-MzbUSahkTW1u7JpKKjY7LCARd1fU5W2rLdxlM4kdkayuCwZImjkpluF9CM1aLewYJguPDqewLam18Y6AU69A8A==", + "dev": true + } + } + }, + "markdownlint-rule-helpers": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/markdownlint-rule-helpers/-/markdownlint-rule-helpers-0.6.0.tgz", + "integrity": "sha512-LiZVAbg9/cqkBHtLNNqHV3xuy4Y2L/KuGU6+ZXqCT9NnCdEkIoxeI5/96t+ExquBY0iHy2CVWxPH16nG1RKQVQ==", + "dev": true + }, "material-colors": { "version": "1.2.6", "resolved": "https://registry.npmjs.org/material-colors/-/material-colors-1.2.6.tgz", @@ -27694,7 +27815,7 @@ "dependencies": { "clone-deep": { "version": "0.2.4", - "resolved": "https://registry.npmjs.org/clone-deep/-/clone-deep-0.2.4.tgz", + "resolved": "http://registry.npmjs.org/clone-deep/-/clone-deep-0.2.4.tgz", "integrity": "sha1-TnPdCen7lxzDhnDF3O2cGJZIHMY=", "dev": true, "requires": { @@ -27728,7 +27849,7 @@ "dependencies": { "kind-of": { "version": "2.0.1", - "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-2.0.1.tgz", + "resolved": "http://registry.npmjs.org/kind-of/-/kind-of-2.0.1.tgz", "integrity": "sha1-AY7HpM5+OobLkUG+UZ0kyPqpgbU=", "dev": true, "requires": { @@ -39104,6 +39225,12 @@ "resolved": "https://registry.npmjs.org/ua-parser-js/-/ua-parser-js-0.7.18.tgz", "integrity": "sha512-LtzwHlVHwFGTptfNSgezHp7WUlwiqb0gA9AALRbKaERfxwJoiX0A73QbTToxteIAuIaFshhgIZfqK8s7clqgnA==" }, + "uc.micro": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-1.0.6.tgz", + "integrity": "sha512-8Y75pvTYkLJW2hWQHXxoqRgV7qb9B+9vFEtidML+7koHUFapnVJAZ6cKs+Qjz5Aw3aZWHMC6u0wJE3At+nSGwA==", + "dev": true + }, "uglify-es": { "version": "3.3.9", "resolved": "https://registry.npmjs.org/uglify-es/-/uglify-es-3.3.9.tgz", diff --git a/package.json b/package.json index c3676ef905b1c..5e62dd5b98547 100644 --- a/package.json +++ b/package.json @@ -197,6 +197,7 @@ "lint-css:fix": "npm run lint-css -- --fix", "lint-types": "tsc", "lint-md": "wp-scripts lint-md", + "lint-md:docs": "wp-scripts lint-md-docs", "package-plugin": "./bin/build-plugin-zip.sh", "pot-to-php": "./bin/pot-to-php.js", "publish:check": "lerna updated", diff --git a/packages/scripts/config/.markdownlint.json b/packages/scripts/config/.markdownlint.json new file mode 100644 index 0000000000000..f5eefa8d99af6 --- /dev/null +++ b/packages/scripts/config/.markdownlint.json @@ -0,0 +1,8 @@ +{ + "default": true, + "MD003": { "style": "atx" }, + "MD007": { "indent": 4 }, + "MD013": { "line_length": 9999 }, + "no-hard-tabs": false, + "whitespace": false +} diff --git a/packages/scripts/package.json b/packages/scripts/package.json index e9514c78f8d4f..2696ea7ac5929 100644 --- a/packages/scripts/package.json +++ b/packages/scripts/package.json @@ -53,6 +53,8 @@ "jest-puppeteer": "^4.3.0", "js-yaml": "^3.13.1", "lodash": "^4.17.15", + "markdownlint": "^0.18.0", + "markdownlint-cli": "^0.21.0", "minimist": "^1.2.0", "npm-package-json-lint": "^4.0.3", "prettier": "npm:wp-prettier@1.19.1", diff --git a/packages/scripts/scripts/lint-md-docs.js b/packages/scripts/scripts/lint-md-docs.js new file mode 100644 index 0000000000000..6458c2b681649 --- /dev/null +++ b/packages/scripts/scripts/lint-md-docs.js @@ -0,0 +1,46 @@ +/** + * External dependencies + */ +const { sync: spawn } = require( 'cross-spawn' ); +const { sync: resolveBin } = require( 'resolve-bin' ); + +/** + * Internal dependencies + */ +const { + fromConfigRoot, + getArgsFromCLI, + hasArgInCLI, + hasFileArgInCLI, + hasProjectFile, +} = require( '../utils' ); + +const args = getArgsFromCLI(); + +const defaultFilesArgs = hasFileArgInCLI() ? [] : [ '**/*.md' ]; + +// See: https://eslint.org/docs/user-guide/configuring#using-configuration-files-1. +const hasLintConfig = hasArgInCLI( '-c' ) || hasArgInCLI( '--config' ); + +// 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 defaultConfigArgs = ! hasLintConfig ? + [ '--config', fromConfigRoot( '.markdownlint.json' ) ] : + []; + +// See: https://eslint.org/docs/user-guide/configuring#ignoring-files-and-directories. +const hasIgnoredFiles = hasArgInCLI( '--ignore' ) || + hasProjectFile( '.markdownlintignore' ); + +const defaultIgnoreArgs = ! hasIgnoredFiles ? + [ '--ignore', 'build', '--ignore', 'node_modules' ] : + []; + +const result = spawn( + resolveBin( 'markdownlint-cli', { executable: 'markdownlint' } ), + [ ...defaultConfigArgs, ...defaultIgnoreArgs, ...args, ...defaultFilesArgs ], + { stdio: 'inherit' } +); + +process.exit( result.status ); From 115a576d7a26bc23a470148db70507e243d9a431 Mon Sep 17 00:00:00 2001 From: Marcus Kazmierczak Date: Mon, 27 Jan 2020 13:54:19 -0800 Subject: [PATCH 02/10] Clarify naming of lint-md scripts js and docs - Updates lint-md scripts to lint-md-js for linting source included in the document and lint-md-docs for linting the markup of the document itself. - Update scripts changelog - Update readme with commands --- package.json | 2 +- packages/scripts/CHANGELOG.md | 4 ++- packages/scripts/README.md | 35 ++++++++++++++++--- .../scripts/{lint-md.js => lint-md-js.js} | 0 4 files changed, 34 insertions(+), 7 deletions(-) rename packages/scripts/scripts/{lint-md.js => lint-md-js.js} (100%) diff --git a/package.json b/package.json index 5e62dd5b98547..d002e8c6c295e 100644 --- a/package.json +++ b/package.json @@ -196,7 +196,7 @@ "lint-css": "wp-scripts lint-style '**/*.scss'", "lint-css:fix": "npm run lint-css -- --fix", "lint-types": "tsc", - "lint-md": "wp-scripts lint-md", + "lint-md:js": "wp-scripts lint-md-js", "lint-md:docs": "wp-scripts lint-md-docs", "package-plugin": "./bin/build-plugin-zip.sh", "pot-to-php": "./bin/pot-to-php.js", diff --git a/packages/scripts/CHANGELOG.md b/packages/scripts/CHANGELOG.md index 2e66f345ebc59..6cf2ebd32f4d0 100644 --- a/packages/scripts/CHANGELOG.md +++ b/packages/scripts/CHANGELOG.md @@ -8,8 +8,10 @@ ### New Features - Add SVGR support to compile SVG files to React components using the `@svgr/webpack` plugin ([#18243](https://github.com/WordPress/gutenberg/pull/18243)). + - Add `format-js` script to format JavaScript source code, it uses the [`wp-prettier`](https://github.com/Automattic/wp-prettier) – Prettier fork adjusted to WordPress coding style guidelines ([#18048](https://github.com/WordPress/gutenberg/pull/18048)). -- Add `lint-md` script to lint JavaScript source code in markdown files, uses the `eslint-plugin-markdown` plugin ([#19518](https://github.com/WordPress/gutenberg/pull/19518)). +- Add `lint-md-js` script to lint JavaScript source code in markdown files, uses the `eslint-plugin-markdown` plugin ([#19518](https://github.com/WordPress/gutenberg/pull/19518)). +- Add `lint-md-docs` script to lint the markup of markdown files, uses the `markdownlint` module ([#19855](https://github.com/WordPress/gutenberg/pull/19855)). - Add `packages-update` script to update WordPress packages to the latest version automatically ([#19448](https://github.com/WordPress/gutenberg/pull/19448)). ## 6.1.1 (2020-01-01) diff --git a/packages/scripts/README.md b/packages/scripts/README.md index 66bfa89c8de69..475f848ef0178 100644 --- a/packages/scripts/README.md +++ b/packages/scripts/README.md @@ -33,7 +33,8 @@ _Example:_ "format:js": "wp-scripts format-js", "lint:css": "wp-scripts lint-style", "lint:js": "wp-scripts lint-js", - "lint:md": "wp-scripts lint-md", + "lint-md:docs": "wp-scripts lint-md-docs", + "lint-md:js": "wp-scripts lint-md-js", "lint:pkg-json": "wp-scripts lint-pkg-json", "packages-update": "wp-scripts packages-update", "start": "wp-scripts start", @@ -251,23 +252,47 @@ By default, files located in `build` and `node_modules` folders are ignored. 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. -### `lint-md` +### `lint-md:docs` -Helps enforce standards for JS source code in your markdown files. +Uses markdownlint to lint the markup of markdown files to enforce standards. _Example:_ ```json { "scripts": { - "lint:md": "wp-scripts lint-md" + "lint-md:docs": "wp-scripts lint-md-docs" } } ``` This is how you execute the script with presented setup: -* `npm run lint:md` - lints markdown files in the entire project’s directories. +* `npm run lint-md:docs` - lints markdown files in the entire project’s directories. + +By default, files located in `build` and `node_modules` folders are ignored. + +#### Advanced information + +It uses [markdownlint](https://github.com/DavidAnson/markdownlint) with the [.markdownlint.json](https://github.com/WordPress/gutenberg/blob/master/packages/scripts/config/.markdownlint.json) configuration. This configuration tunes the linting rules to match WordPress standard, you can override with your own config, see [markdownlint-cli](https://github.com/igorshubovych/markdownlint-cli/) for command-line parameters. + +### `lint-md:js` + +Uses eslint to lint the source included in markdown files to enforce standards for JS code. + +_Example:_ + +```json +{ + "scripts": { + "lint-md:js": "wp-scripts lint-md-js" + } +} +``` + +This is how you execute the script with presented setup: + +* `npm run lint-md:js` - lints markdown files in the entire project’s directories. By default, files located in `build` and `node_modules` folders are ignored. diff --git a/packages/scripts/scripts/lint-md.js b/packages/scripts/scripts/lint-md-js.js similarity index 100% rename from packages/scripts/scripts/lint-md.js rename to packages/scripts/scripts/lint-md-js.js From abd295531020975ca270cd354aa8b25cbbb70e48 Mon Sep 17 00:00:00 2001 From: Marcus Kazmierczak Date: Tue, 28 Jan 2020 14:41:08 -0800 Subject: [PATCH 03/10] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Grzegorz (Greg) Ziółkowski --- packages/scripts/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/scripts/README.md b/packages/scripts/README.md index 475f848ef0178..808fa613e37d1 100644 --- a/packages/scripts/README.md +++ b/packages/scripts/README.md @@ -252,7 +252,7 @@ By default, files located in `build` and `node_modules` folders are ignored. 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. -### `lint-md:docs` +### `lint-md-docs` Uses markdownlint to lint the markup of markdown files to enforce standards. @@ -276,9 +276,9 @@ By default, files located in `build` and `node_modules` folders are ignored. It uses [markdownlint](https://github.com/DavidAnson/markdownlint) with the [.markdownlint.json](https://github.com/WordPress/gutenberg/blob/master/packages/scripts/config/.markdownlint.json) configuration. This configuration tunes the linting rules to match WordPress standard, you can override with your own config, see [markdownlint-cli](https://github.com/igorshubovych/markdownlint-cli/) for command-line parameters. -### `lint-md:js` +### `lint-md-js` -Uses eslint to lint the source included in markdown files to enforce standards for JS code. +Uses ESLint to lint the source included in markdown files to enforce standards for JS code. _Example:_ From 697570926833cf1a22381ab6bd4252943b1cf2d6 Mon Sep 17 00:00:00 2001 From: Marcus Kazmierczak Date: Tue, 28 Jan 2020 14:43:11 -0800 Subject: [PATCH 04/10] Fix URL for markdownlint CLI --- packages/scripts/scripts/lint-md-docs.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/scripts/scripts/lint-md-docs.js b/packages/scripts/scripts/lint-md-docs.js index 6458c2b681649..582dd6b7fca9d 100644 --- a/packages/scripts/scripts/lint-md-docs.js +++ b/packages/scripts/scripts/lint-md-docs.js @@ -19,17 +19,16 @@ const args = getArgsFromCLI(); const defaultFilesArgs = hasFileArgInCLI() ? [] : [ '**/*.md' ]; -// See: https://eslint.org/docs/user-guide/configuring#using-configuration-files-1. +// See: https://github.com/igorshubovych/markdownlint-cli#usage const hasLintConfig = hasArgInCLI( '-c' ) || hasArgInCLI( '--config' ); // 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. +// provided with the scripts module. const defaultConfigArgs = ! hasLintConfig ? [ '--config', fromConfigRoot( '.markdownlint.json' ) ] : []; -// See: https://eslint.org/docs/user-guide/configuring#ignoring-files-and-directories. +// See: https://github.com/igorshubovych/markdownlint-cli#ignoring-files const hasIgnoredFiles = hasArgInCLI( '--ignore' ) || hasProjectFile( '.markdownlintignore' ); From 120ca16d9a28793a92818dc99b36467496c6466b Mon Sep 17 00:00:00 2001 From: Marcus Kazmierczak Date: Tue, 28 Jan 2020 14:50:09 -0800 Subject: [PATCH 05/10] Add -i check, details around ignore on CLI --- packages/scripts/scripts/lint-md-docs.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/scripts/scripts/lint-md-docs.js b/packages/scripts/scripts/lint-md-docs.js index 582dd6b7fca9d..39ef7b6f3757b 100644 --- a/packages/scripts/scripts/lint-md-docs.js +++ b/packages/scripts/scripts/lint-md-docs.js @@ -29,9 +29,14 @@ const defaultConfigArgs = ! hasLintConfig ? []; // See: https://github.com/igorshubovych/markdownlint-cli#ignoring-files -const hasIgnoredFiles = hasArgInCLI( '--ignore' ) || +const hasIgnoredFiles = hasArgInCLI( '--ignore' ) || hasArgInCLI( '-i' ) || hasProjectFile( '.markdownlintignore' ); +// Default ignore [ build, node_modules ] directories +// TODO: Once https://github.com/igorshubovych/markdownlint-cli/issues/46 is in +// we can switch this to specify an ignore file on the command-line. By default, +// markdownlint looks for .markdownlintignore in project direcotry, but how our +// scripts work we store the configs in the scripts/config directory const defaultIgnoreArgs = ! hasIgnoredFiles ? [ '--ignore', 'build', '--ignore', 'node_modules' ] : []; From f760e460b4ac9b0537910bdf8decee12857bd1ad Mon Sep 17 00:00:00 2001 From: Marcus Kazmierczak Date: Tue, 28 Jan 2020 14:55:34 -0800 Subject: [PATCH 06/10] Check for additional project config files --- packages/scripts/scripts/lint-md-docs.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/scripts/scripts/lint-md-docs.js b/packages/scripts/scripts/lint-md-docs.js index 39ef7b6f3757b..69532986bb406 100644 --- a/packages/scripts/scripts/lint-md-docs.js +++ b/packages/scripts/scripts/lint-md-docs.js @@ -19,8 +19,12 @@ const args = getArgsFromCLI(); const defaultFilesArgs = hasFileArgInCLI() ? [] : [ '**/*.md' ]; -// See: https://github.com/igorshubovych/markdownlint-cli#usage -const hasLintConfig = hasArgInCLI( '-c' ) || hasArgInCLI( '--config' ); +// See: https://github.com/igorshubovych/markdownlint-cli#configuration +// Check if specified on command-line or project file for config +const hasLintConfig = hasArgInCLI( '-c' ) || hasArgInCLI( '--config' ) || + hasProjectFile( '.markdownlint.json' ) || + hasProjectFile( '.markdownlint.yaml' ) || + hasProjectFile( '.markdownlint.yml' ); // When a configuration is not provided by the project, use from the default // provided with the scripts module. @@ -29,6 +33,7 @@ const defaultConfigArgs = ! hasLintConfig ? []; // See: https://github.com/igorshubovych/markdownlint-cli#ignoring-files +// Check if ignore specified on command-line or project file const hasIgnoredFiles = hasArgInCLI( '--ignore' ) || hasArgInCLI( '-i' ) || hasProjectFile( '.markdownlintignore' ); From 299faf87a5398e562c35b4de0c65b19b17da838a Mon Sep 17 00:00:00 2001 From: Marcus Kazmierczak Date: Tue, 28 Jan 2020 14:57:01 -0800 Subject: [PATCH 07/10] Update script commands to all for lint:* --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index d002e8c6c295e..2124fac1debc7 100644 --- a/package.json +++ b/package.json @@ -196,8 +196,8 @@ "lint-css": "wp-scripts lint-style '**/*.scss'", "lint-css:fix": "npm run lint-css -- --fix", "lint-types": "tsc", - "lint-md:js": "wp-scripts lint-md-js", - "lint-md:docs": "wp-scripts lint-md-docs", + "lint:md-js": "wp-scripts lint-md-js", + "lint:md-docs": "wp-scripts lint-md-docs", "package-plugin": "./bin/build-plugin-zip.sh", "pot-to-php": "./bin/pot-to-php.js", "publish:check": "lerna updated", From 64921bdc8da06e7c48605676f551f2c4b5de88c6 Mon Sep 17 00:00:00 2001 From: Grzegorz Ziolkowski Date: Wed, 29 Jan 2020 08:07:07 +0100 Subject: [PATCH 08/10] Local changes applied to package-lock.json --- package-lock.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1781227b53582..9e47750359a4e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -27815,7 +27815,7 @@ "dependencies": { "clone-deep": { "version": "0.2.4", - "resolved": "http://registry.npmjs.org/clone-deep/-/clone-deep-0.2.4.tgz", + "resolved": "https://registry.npmjs.org/clone-deep/-/clone-deep-0.2.4.tgz", "integrity": "sha1-TnPdCen7lxzDhnDF3O2cGJZIHMY=", "dev": true, "requires": { @@ -27849,7 +27849,7 @@ "dependencies": { "kind-of": { "version": "2.0.1", - "resolved": "http://registry.npmjs.org/kind-of/-/kind-of-2.0.1.tgz", + "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-2.0.1.tgz", "integrity": "sha1-AY7HpM5+OobLkUG+UZ0kyPqpgbU=", "dev": true, "requires": { From 07d1ea3f350e44cd06cf61d7d64bcffe6f64e03b Mon Sep 17 00:00:00 2001 From: Marcus Kazmierczak Date: Wed, 29 Jan 2020 05:44:56 -0800 Subject: [PATCH 09/10] Update packages/scripts/README.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Grzegorz (Greg) Ziółkowski --- packages/scripts/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/scripts/README.md b/packages/scripts/README.md index 808fa613e37d1..d3ab0b7001b14 100644 --- a/packages/scripts/README.md +++ b/packages/scripts/README.md @@ -33,7 +33,7 @@ _Example:_ "format:js": "wp-scripts format-js", "lint:css": "wp-scripts lint-style", "lint:js": "wp-scripts lint-js", - "lint-md:docs": "wp-scripts lint-md-docs", + "lint:md:docs": "wp-scripts lint-md-docs", "lint-md:js": "wp-scripts lint-md-js", "lint:pkg-json": "wp-scripts lint-pkg-json", "packages-update": "wp-scripts packages-update", From 75723ba83a6db4ea29ae6e3f67e696d165375539 Mon Sep 17 00:00:00 2001 From: Marcus Kazmierczak Date: Wed, 29 Jan 2020 05:45:52 -0800 Subject: [PATCH 10/10] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Thanks for the review and updates :+1: Co-Authored-By: Grzegorz (Greg) Ziółkowski --- packages/scripts/README.md | 10 +++++----- packages/scripts/scripts/lint-md-docs.js | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/scripts/README.md b/packages/scripts/README.md index d3ab0b7001b14..261106c895c28 100644 --- a/packages/scripts/README.md +++ b/packages/scripts/README.md @@ -34,7 +34,7 @@ _Example:_ "lint:css": "wp-scripts lint-style", "lint:js": "wp-scripts lint-js", "lint:md:docs": "wp-scripts lint-md-docs", - "lint-md:js": "wp-scripts lint-md-js", + "lint:md:js": "wp-scripts lint-md-js", "lint:pkg-json": "wp-scripts lint-pkg-json", "packages-update": "wp-scripts packages-update", "start": "wp-scripts start", @@ -261,14 +261,14 @@ _Example:_ ```json { "scripts": { - "lint-md:docs": "wp-scripts lint-md-docs" + "lint:md:docs": "wp-scripts lint-md-docs" } } ``` This is how you execute the script with presented setup: -* `npm run lint-md:docs` - lints markdown files in the entire project’s directories. +* `npm run lint:md:docs` - lints markdown files in the entire project’s directories. By default, files located in `build` and `node_modules` folders are ignored. @@ -285,14 +285,14 @@ _Example:_ ```json { "scripts": { - "lint-md:js": "wp-scripts lint-md-js" + "lint:md:js": "wp-scripts lint-md-js" } } ``` This is how you execute the script with presented setup: -* `npm run lint-md:js` - lints markdown files in the entire project’s directories. +* `npm run lint:md:js` - lints markdown files in the entire project’s directories. By default, files located in `build` and `node_modules` folders are ignored. diff --git a/packages/scripts/scripts/lint-md-docs.js b/packages/scripts/scripts/lint-md-docs.js index 69532986bb406..c2949985cb35c 100644 --- a/packages/scripts/scripts/lint-md-docs.js +++ b/packages/scripts/scripts/lint-md-docs.js @@ -43,7 +43,7 @@ const hasIgnoredFiles = hasArgInCLI( '--ignore' ) || hasArgInCLI( '-i' ) || // markdownlint looks for .markdownlintignore in project direcotry, but how our // scripts work we store the configs in the scripts/config directory const defaultIgnoreArgs = ! hasIgnoredFiles ? - [ '--ignore', 'build', '--ignore', 'node_modules' ] : + [ '--ignore', '**/build/**', '--ignore', '**/node_modules/**' ] : []; const result = spawn(