Skip to content

feat: add ESLint config for markdown linting with eslint-plugin-markdown #3140

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
26 changes: 26 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// eslint.config.js
const markdown = require('eslint-plugin-markdown');

module.exports = [
{
plugins: {
markdown,
},
},
{
files: ['**/*.md'],
processor: 'markdown/markdown',
},
{
files: ['**/*.md/*.js'],
languageOptions: {
ecmaVersion: 2021,
sourceType: 'module',
},
rules: {
semi: ['error', 'always'],
'no-unused-vars': 'warn',
'no-undef': 'error',
},
},
];
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
},
"homepage": "https://github.com/airbnb/javascript",
"devDependencies": {
"eslint": "^9.31.0",
"eslint-plugin-markdown": "^5.1.0",
"markdownlint": "^0.29.0",
"markdownlint-cli": "^0.35.0"
}
Expand Down
19 changes: 19 additions & 0 deletions packages/eslint-config-airbnb-base/rules/imports.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,4 +280,23 @@ module.exports = {
// TODO, semver-minor: enable
'import/no-empty-named-blocks': 'off',
},
plugins: ["markdown"],
overrides: [
{
// Step 2a: Extract code blocks from markdown
files: ["**/*.md"],
processor: "markdown/markdown"
},
{
// Step 2b: Apply JS rules to those code blocks
files: ["**/*.md/*.js"],
rules: {
// Allow console logs in docs
"no-console": "off",
// Don't bother with unresolved imports in examples
"import/no-unresolved": "off"
}
}
// ...other overrides or rules
],
};