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

Add linting of source in markdown files #19518

Merged
merged 6 commits into from
Jan 9, 2020
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
63 changes: 63 additions & 0 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 @@ -189,6 +189,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",
"package-plugin": "./bin/build-plugin-zip.sh",
"pot-to-php": "./bin/pot-to-php.js",
"publish:check": "lerna updated",
Expand Down
19 changes: 19 additions & 0 deletions packages/scripts/config/.eslintrc-md.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// eslint config for markdown documentation

// This configuration is used when parsing JS code blocks
// in documentation. It attempts to allow for snippets of
// codes which may define variables unused, or use variables
// that are assumed to be defined.
module.exports = {
root: true,
plugins: [
'markdown',
],
extends: [
'plugin:@wordpress/eslint-plugin/recommended',
],
"rules": {
"no-undef": "off",
"no-unused-vars": "off"
},
};
1 change: 1 addition & 0 deletions packages/scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"cross-spawn": "^5.1.0",
"decompress-zip": "^0.2.2",
"eslint": "^6.1.0",
"eslint-plugin-markdown": "1.0.1",
"jest": "^24.7.1",
"jest-puppeteer": "^4.3.0",
"js-yaml": "^3.13.1",
Expand Down
46 changes: 46 additions & 0 deletions packages/scripts/scripts/lint-md.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 ?
[ '--no-eslintrc', '--config', fromConfigRoot( '.eslintrc-md.js' ) ] :
[];

// See: https://eslint.org/docs/user-guide/configuring#ignoring-files-and-directories.
const hasIgnoredFiles = hasArgInCLI( '--ignore-path' ) ||
hasProjectFile( '.eslintignore' );

const defaultIgnoreArgs = ! hasIgnoredFiles ?
[ '--ignore-path', fromConfigRoot( '.eslintignore' ) ] :
[];

const result = spawn(
resolveBin( 'eslint' ),
[ ...defaultConfigArgs, ...defaultIgnoreArgs, ...args, ...defaultFilesArgs ],
{ stdio: 'inherit' }
);

process.exit( result.status );