Skip to content

Add eslint-plugin-markdown for JavaScript code samples in documentation #134

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

Merged
merged 1 commit into from
Jun 18, 2021
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
35 changes: 29 additions & 6 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

module.exports = {
root: true,
plugins: ['node', 'self'],
plugins: ['node'],
extends: [
'not-an-aardvark/node',
'plugin:node/recommended',
'plugin:self/all',
'plugin:unicorn/recommended',
],
parserOptions: {
Expand All @@ -24,10 +23,6 @@ module.exports = {
],
'require-jsdoc': 'error',

'self/meta-property-ordering': 'off',
'self/require-meta-docs-url': 'off',
'self/report-message-format': ['error', '^[^a-z].*.$'],

'unicorn/consistent-function-scoping': 'off',
'unicorn/no-array-callback-reference': 'off',
'unicorn/no-array-for-each': 'off',
Expand All @@ -37,9 +32,37 @@ module.exports = {
'unicorn/prevent-abbreviations': 'off',
},
overrides: [
{
// Apply eslint-plugin rules to our own rules/tests (but not docs).
files: ['lib/**/*.js', 'tests/**/*.js'],
plugins: ['self'],
extends: ['plugin:self/all'],
rules: {
'self/meta-property-ordering': 'off',
'self/report-message-format': ['error', '^[^a-z].*.$'],
'self/require-meta-docs-url': 'off',
},
},
{
files: ['tests/**/*.js'],
env: { mocha: true },
},
{
files: ['**/*.md'],
processor: 'markdown/markdown',
},
{
// Markdown JS code samples in documentation:
files: ['**/*.md/*.js'],
plugins: ['markdown'],
noInlineConfig: true,
rules: {
'no-undef': 'off',
'no-unused-vars': 'off',
strict: 'off',

'unicorn/filename-case': 'off',
},
},
],
};
20 changes: 9 additions & 11 deletions docs/rules/consistent-output.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ new RuleTester().run('example-rule', rule, {
{
code: 'foo',
output: 'bar',
errors: ['baz']
errors: ['baz'],
},
{
code: 'bar',
errors: ['baz']
}
]
errors: ['baz'],
},
],
});

```

Examples of **correct** code for this rule:
Expand All @@ -43,21 +42,20 @@ new RuleTester().run('example-rule', rule, {
{
code: 'foo',
output: 'bar',
errors: ['baz']
errors: ['baz'],
},
{
code: 'bar',
output: 'qux',
errors: ['baz']
errors: ['baz'],
},
{
code: 'foo',
output: null, // asserts that there is no autofix
errors: ['baz']
}
]
errors: ['baz'],
},
],
});

```

## Options
Expand Down
30 changes: 16 additions & 14 deletions docs/rules/fixer-return.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,31 @@ Examples of **incorrect** code for this rule:

```js
/* eslint eslint-plugin/fixer-return: error */

module.exports = {
create: function(context) {
context.report( {
fix: function(fixer) {
fixer.foo();
}
});
}
create (context) {
context.report({
fix (fixer) {
fixer.foo();
},
});
},
};
```

Examples of **correct** code for this rule:

```js
/* eslint eslint-plugin/fixer-return: error */

module.exports = {
create: function(context) {
context.report( {
fix: function(fixer) {
return fixer.foo();
}
});
}
create (context) {
context.report({
fix (fixer) {
return fixer.foo();
},
});
},
};
```

Expand Down
34 changes: 17 additions & 17 deletions docs/rules/meta-property-ordering.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@ Examples of **incorrect** code for this rule:
// invalid; wrong order.
module.exports = {
meta: {
docs: "",
type: "problem",
fixable: "code",
docs: '',
type: 'problem',
fixable: 'code',
},
create() {},
}
create () {},
};

// invalid; extra properties must be placed afterwards.
module.exports = {
meta: {
type: "problem",
fooooooooo: "foo",
docs: "",
fixable: "code",
type: 'problem',
fooooooooo: 'foo',
docs: '',
fixable: 'code',
},
create() {},
}
create () {},
};
```

Examples of **correct** code for this rule:
Expand All @@ -52,13 +52,13 @@ Examples of **correct** code for this rule:
// valid;
module.exports = {
meta: {
type: "bar",
docs: "foo",
messages: ["zoo"],
fooooooooo: "foo",
type: 'bar',
docs: 'foo',
messages: ['zoo'],
fooooooooo: 'foo',
},
create() {},
}
create () {},
};
```

## When Not To Use It
Expand Down
22 changes: 11 additions & 11 deletions docs/rules/no-deprecated-context-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,29 @@ Examples of **incorrect** code for this rule:

```js
module.exports = {
create(context) {
create (context) {
return {
Program(node) {
Program (node) {
const firstToken = context.getFirstToken(node);
}
}
}
}
},
};
},
};
```

Examples of **correct** code for this rule:

```js
module.exports = {
create(context) {
create (context) {
const sourceCode = context.getSourceCode();

return {
Program(node) {
Program (node) {
const firstToken = sourceCode.getFirstToken(node);
}
}
}
},
};
},
};
```

Expand Down
14 changes: 4 additions & 10 deletions docs/rules/no-deprecated-report-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,9 @@ The following patterns are considered warnings:

```js
module.exports = {
create(context) {

create (context) {
context.report(node, 'This node is bad.');

context.report(node, loc, 'This node is bad.');

}
},
};

```
Expand All @@ -27,13 +23,11 @@ The following patterns are not warnings:

```js
module.exports = {
create(context) {

create (context) {
context.report({ node, message: 'This node is bad.' });

context.report({ node, loc, message: 'This node is bad.' });

}
},
};
```

Expand Down
34 changes: 16 additions & 18 deletions docs/rules/no-identical-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,29 @@ When a rule has a lot of tests, it's sometimes difficult to tell if any tests ar
Examples of **incorrect** code for this rule:

```js
/* eslint eslint-plugin/no-identical-tests: error */
new RuleTester().run('foo', bar, {
valid: [
{ code: 'foo' },
{ code: 'foo' }
],
invalid: []
/* eslint eslint-plugin/no-identical-tests: error */

new RuleTester().run('foo', bar, {
valid: [
{ code: 'foo' },
{ code: 'foo' },
],
invalid: [],
});

```

Examples of **correct** code for this rule:

```js
/* eslint eslint-plugin/no-identical-tests: error */
new RuleTester().run('foo', bar, {
valid: [
{ code: 'foo' },
{ code: 'bar' }
],
invalid: []
/* eslint eslint-plugin/no-identical-tests: error */

new RuleTester().run('foo', bar, {
valid: [
{ code: 'foo' },
{ code: 'bar' },
],
invalid: [],
});

```

## When Not To Use It
Expand Down
24 changes: 11 additions & 13 deletions docs/rules/no-missing-placeholders.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Report messages in rules can have placeholders surrounded by curly brackets.
context.report({
node,
message: '{{disallowedNode}} nodes are not allowed.',
data: { disallowedNode: node.type }
data: { disallowedNode: node.type },
});

// Resulting message: e.g. 'IfStatement nodes are not allowed.'
Expand All @@ -21,49 +21,47 @@ This rule aims to disallow missing placeholders in rule report messages.
Examples of **incorrect** code for this rule:

```js
/*eslint eslint-plugin/no-missing-placeholders: error*/
/* eslint eslint-plugin/no-missing-placeholders: error*/

module.exports = {
create(context) {
create (context) {
context.report({
node,
message: '{{something}} is wrong.'
message: '{{something}} is wrong.',
});

context.report({
node,
message: '{{something}} is wrong.',
data: { somethingElse: 'foo' }
data: { somethingElse: 'foo' },
});

context.report(node, '{{something}} is wrong.', { somethingElse: 'foo' });
}
},
};

```

Examples of **correct** code for this rule:

```js
/*eslint eslint-plugin/no-missing-placeholders: error*/
/* eslint eslint-plugin/no-missing-placeholders: error*/

module.exports = {
create(context) {
create (context) {
context.report({
node,
message: 'something is wrong.'
message: 'something is wrong.',
});

context.report({
node,
message: '{{something}} is wrong.',
data: { something: 'foo' }
data: { something: 'foo' },
});

context.report(node, '{{something}} is wrong.', { something: 'foo' });
}
},
};

```

## When Not To Use It
Expand Down
Loading