Skip to content

Commit

Permalink
Add markdownlint script to lint docs markup
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mkaz committed Jan 29, 2020
1 parent 7c32ac9 commit 36fd62b
Show file tree
Hide file tree
Showing 6 changed files with 195 additions and 2 deletions.
9 changes: 9 additions & 0 deletions .markdownlintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
bin
build
node_modules
phpunit
playground
storybook
test
vendor
wordpress
131 changes: 129 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 8 additions & 0 deletions packages/scripts/config/.markdownlint.json
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
}
2 changes: 2 additions & 0 deletions packages/scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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]",
Expand Down
46 changes: 46 additions & 0 deletions packages/scripts/scripts/lint-md-docs.js
Original file line number Diff line number Diff line change
@@ -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 );

0 comments on commit 36fd62b

Please sign in to comment.