forked from WordPress/gutenberg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add markdownlint script to lint docs markup (WordPress#19855)
* 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 WordPress#12426 * 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 * Apply suggestions from code review Co-Authored-By: Grzegorz (Greg) Ziółkowski <[email protected]> * Fix URL for markdownlint CLI * Add -i check, details around ignore on CLI * Check for additional project config files * Update script commands to all for lint:* * Local changes applied to package-lock.json * Update packages/scripts/README.md Co-Authored-By: Grzegorz (Greg) Ziółkowski <[email protected]> * Apply suggestions from code review Thanks for the review and updates 👍 Co-Authored-By: Grzegorz (Greg) Ziółkowski <[email protected]> Co-authored-by: Grzegorz (Greg) Ziółkowski <[email protected]>
- Loading branch information
Showing
9 changed files
with
236 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
bin | ||
build | ||
node_modules | ||
phpunit | ||
playground | ||
storybook | ||
test | ||
vendor | ||
wordpress |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"default": true, | ||
"MD003": { "style": "atx" }, | ||
"MD007": { "indent": 4 }, | ||
"MD013": { "line_length": 9999 }, | ||
"no-hard-tabs": false, | ||
"whitespace": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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:[email protected]", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* 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://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. | ||
const defaultConfigArgs = ! hasLintConfig ? | ||
[ '--config', fromConfigRoot( '.markdownlint.json' ) ] : | ||
[]; | ||
|
||
// 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' ); | ||
|
||
// 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/**' ] : | ||
[]; | ||
|
||
const result = spawn( | ||
resolveBin( 'markdownlint-cli', { executable: 'markdownlint' } ), | ||
[ ...defaultConfigArgs, ...defaultIgnoreArgs, ...args, ...defaultFilesArgs ], | ||
{ stdio: 'inherit' } | ||
); | ||
|
||
process.exit( result.status ); |
File renamed without changes.