Skip to content

Commit

Permalink
chore: add prettier (#234)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmish authored Dec 9, 2021
1 parent 6d56188 commit c4fdffe
Show file tree
Hide file tree
Showing 72 changed files with 2,495 additions and 1,216 deletions.
7 changes: 6 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@

module.exports = {
root: true,
parserOptions: {
ecmaVersion: 2021,
sourceType: 'script',
},
extends: [
'not-an-aardvark/node',
'plugin:unicorn/recommended',
'plugin:node/recommended',
'plugin:prettier/recommended',
'plugin:unicorn/recommended',
],
rules: {
'comma-dangle': [
Expand Down
5 changes: 5 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

module.exports = {
singleQuote: true,
};
44 changes: 28 additions & 16 deletions build/generate-readme-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,47 @@ const END_TABLE_MARKER = '\n<!-- __END AUTOGENERATED TABLE__ -->';

const expectedTableLines = Object.keys(rules)
.sort()
.reduce((lines, ruleId) => {
const rule = rules[ruleId];

lines.push([
`[${ruleId}](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/${ruleId}.md)`,
rule.meta.docs.recommended ? '✔️' : '',
rule.meta.fixable ? '🛠' : '',
rule.meta.hasSuggestions ? '💡' : '',
rule.meta.docs.description,
].join(' | '));

return lines;
}, ['Name | ✔️ | 🛠 | 💡 | Description', '----- | ----- | ----- | ----- | -----'])
.reduce(
(lines, ruleId) => {
const rule = rules[ruleId];

lines.push(
[
`[${ruleId}](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/${ruleId}.md)`,
rule.meta.docs.recommended ? '✔️' : '',
rule.meta.fixable ? '🛠' : '',
rule.meta.hasSuggestions ? '💡' : '',
rule.meta.docs.description,
].join(' | ')
);

return lines;
},
[
'Name | ✔️ | 🛠 | 💡 | Description',
'----- | ----- | ----- | ----- | -----',
]
)
.join('\n');

const readmeContents = fs.readFileSync(README_LOCATION, 'utf8');

if (!readmeContents.includes(BEGIN_TABLE_MARKER)) {
throw new Error(`Could not find '${BEGIN_TABLE_MARKER}' marker in README.md.`);
throw new Error(
`Could not find '${BEGIN_TABLE_MARKER}' marker in README.md.`
);
}

if (!readmeContents.includes(END_TABLE_MARKER)) {
throw new Error(`Could not find '${END_TABLE_MARKER}' marker in README.md.`);
}

const linesStartIndex = readmeContents.indexOf(BEGIN_TABLE_MARKER) + BEGIN_TABLE_MARKER.length;
const linesStartIndex =
readmeContents.indexOf(BEGIN_TABLE_MARKER) + BEGIN_TABLE_MARKER.length;
const linesEndIndex = readmeContents.indexOf(END_TABLE_MARKER);

const updatedReadmeContents = readmeContents.slice(0, linesStartIndex) +
const updatedReadmeContents =
readmeContents.slice(0, linesStartIndex) +
expectedTableLines +
readmeContents.slice(linesEndIndex);

Expand Down
12 changes: 6 additions & 6 deletions docs/rules/fixer-return.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ Examples of **incorrect** code for this rule:
/* eslint eslint-plugin/fixer-return: error */

module.exports = {
create (context) {
create(context) {
context.report({
fix (fixer) {
fix(fixer) {
fixer.insertTextAfter(node, 'foo');
},
});
Expand All @@ -30,9 +30,9 @@ Examples of **correct** code for this rule:
/* eslint eslint-plugin/fixer-return: error */

module.exports = {
create (context) {
create(context) {
context.report({
fix (fixer) {
fix(fixer) {
return fixer.insertTextAfter(node, 'foo');
},
});
Expand All @@ -44,9 +44,9 @@ module.exports = {
/* eslint eslint-plugin/fixer-return: error */

module.exports = {
create (context) {
create(context) {
context.report({
fix (fixer) {
fix(fixer) {
if (foo) {
return; // no autofix in this situation
}
Expand Down
7 changes: 3 additions & 4 deletions docs/rules/meta-property-ordering.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ This rule has an array option:
Examples of **incorrect** code for this rule:

```js

/* eslint eslint-plugin/meta-property-ordering: ["error",
["type", "docs", "fixable", "schema", "messages"]
] */
Expand All @@ -27,7 +26,7 @@ module.exports = {
type: 'problem',
fixable: 'code',
},
create () {},
create() {},
};

// invalid; extra properties must be placed afterwards.
Expand All @@ -38,7 +37,7 @@ module.exports = {
docs: '',
fixable: 'code',
},
create () {},
create() {},
};
```

Expand All @@ -57,7 +56,7 @@ module.exports = {
messages: ['zoo'],
fooooooooo: 'foo',
},
create () {},
create() {},
};
```

Expand Down
8 changes: 4 additions & 4 deletions docs/rules/no-deprecated-context-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ Examples of **incorrect** code for this rule:

```js
module.exports = {
create (context) {
create(context) {
return {
Program (ast) {
Program(ast) {
const firstToken = context.getFirstToken(ast);
},
};
Expand All @@ -51,11 +51,11 @@ Examples of **correct** code for this rule:

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

return {
Program (ast) {
Program(ast) {
const firstToken = sourceCode.getFirstToken(ast);
},
};
Expand Down
5 changes: 2 additions & 3 deletions docs/rules/no-deprecated-report-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,17 @@ Examples of **incorrect** code for this rule:

```js
module.exports = {
create (context) {
create(context) {
context.report(node, 'This node is bad.');
},
};

```

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

```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
10 changes: 2 additions & 8 deletions docs/rules/no-identical-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ Examples of **incorrect** code for this rule:
/* eslint eslint-plugin/no-identical-tests: error */

new RuleTester().run('foo', bar, {
valid: [
{ code: 'foo' },
{ code: 'foo' },
],
valid: [{ code: 'foo' }, { code: 'foo' }],
invalid: [],
});
```
Expand All @@ -28,10 +25,7 @@ Examples of **correct** code for this rule:
/* eslint eslint-plugin/no-identical-tests: error */

new RuleTester().run('foo', bar, {
valid: [
{ code: 'foo' },
{ code: 'bar' },
],
valid: [{ code: 'foo' }, { code: 'bar' }],
invalid: [],
});
```
Expand Down
4 changes: 2 additions & 2 deletions docs/rules/no-missing-placeholders.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Examples of **incorrect** code for this rule:
/* eslint eslint-plugin/no-missing-placeholders: error*/

module.exports = {
create (context) {
create(context) {
context.report({
node,
message: '{{something}} is wrong.',
Expand All @@ -49,7 +49,7 @@ Examples of **correct** code for this rule:
/* eslint eslint-plugin/no-missing-placeholders: error*/

module.exports = {
create (context) {
create(context) {
context.report({
node,
message: 'something is wrong.',
Expand Down
13 changes: 7 additions & 6 deletions docs/rules/no-only-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ ruleTester.run('my-rule', myRule, {
{
code: 'const invalid = 42;',
only: true,
errors: [/* ... */],
errors: [
/* ... */
],
},
],
});
Expand All @@ -45,14 +47,13 @@ const { RuleTester } = require('eslint');
const ruleTester = new RuleTester();

ruleTester.run('my-rule', myRule, {
valid: [
'const valid = 42;',
{ code: 'const valid = 42;' },
],
valid: ['const valid = 42;', { code: 'const valid = 42;' }],
invalid: [
{
code: 'const invalid = 42;',
errors: [/* ... */],
errors: [
/* ... */
],
},
],
});
Expand Down
4 changes: 2 additions & 2 deletions docs/rules/no-unused-placeholders.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Examples of **incorrect** code for this rule:
/* eslint eslint-plugin/no-unused-placeholders: error*/

module.exports = {
create (context) {
create(context) {
context.report({
node,
message: 'something is wrong.',
Expand All @@ -32,7 +32,7 @@ Examples of **correct** code for this rule:
/* eslint eslint-plugin/no-unused-placeholders: error*/

module.exports = {
create (context) {
create(context) {
context.report({
node,
message: 'something is wrong.',
Expand Down
4 changes: 2 additions & 2 deletions docs/rules/no-useless-token-range.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Examples of **incorrect** code for this rule:
/* eslint eslint-plugin/no-useless-token-range: error */

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

const rangeStart = sourceCode.getFirstToken(node).range[0];
Expand All @@ -31,7 +31,7 @@ Examples of **correct** code for this rule:
/* eslint eslint-plugin/no-useless-token-range: error */

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

const rangeStart = node.range[0];
Expand Down
8 changes: 4 additions & 4 deletions docs/rules/prefer-message-ids.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ Examples of **incorrect** code for this rule:
/* eslint eslint-plugin/prefer-message-ids: error */

module.exports = {
create (context) {
create(context) {
return {
CallExpression (node) {
CallExpression(node) {
context.report({
node,
message: 'Some error message.',
Expand All @@ -39,9 +39,9 @@ module.exports = {
someMessageId: 'Some error message',
},
},
create (context) {
create(context) {
return {
CallExpression (node) {
CallExpression(node) {
context.report({
node,
messageId: 'someMessageId',
Expand Down
Loading

0 comments on commit c4fdffe

Please sign in to comment.