Skip to content

Commit

Permalink
tools: enforce use of trailing commas in tools/
Browse files Browse the repository at this point in the history
PR-URL: #45889
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
  • Loading branch information
aduh95 authored and targos committed Jan 1, 2023
1 parent a482d8f commit 070a5f7
Show file tree
Hide file tree
Showing 41 changed files with 128 additions and 121 deletions.
14 changes: 4 additions & 10 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ module.exports = {
files: ['**/*.md/*.cjs', '**/*.md/*.js'],
parserOptions: {
sourceType: 'script',
ecmaFeatures: { impliedStrict: true }
ecmaFeatures: { impliedStrict: true },
},
rules: { strict: 'off' },
},
Expand Down Expand Up @@ -103,11 +103,11 @@ module.exports = {
},
{
name: 'Buffer',
message: 'Import Buffer instead of using the global'
message: 'Import Buffer instead of using the global',
},
{
name: 'process',
message: 'Import process instead of using the global'
message: 'Import process instead of using the global',
},
] },
},
Expand All @@ -134,13 +134,7 @@ module.exports = {
ignorePattern: '.*',
},
}],
'comma-dangle': ['error', {
arrays: 'always-multiline',
exports: 'only-multiline',
functions: 'only-multiline',
imports: 'only-multiline',
objects: 'only-multiline',
}],
'comma-dangle': ['error', 'always-multiline'],
'comma-spacing': 'error',
'comma-style': 'error',
'computed-property-spacing': 'error',
Expand Down
7 changes: 7 additions & 0 deletions benchmark/.eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,11 @@ env:
es6: true

rules:
comma-dangle: [error, {
arrays: always-multiline,
exports: only-multiline,
functions: only-multiline,
imports: only-multiline,
objects: only-multiline,
}]
prefer-arrow-callback: error
1 change: 0 additions & 1 deletion doc/.eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@ rules:

# Stylistic Issues
no-multiple-empty-lines: [error, {max: 1, maxEOF: 0, maxBOF: 0}]
comma-dangle: [error, always-multiline]
7 changes: 7 additions & 0 deletions lib/.eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ env:
es6: true

rules:
comma-dangle: [error, {
arrays: always-multiline,
exports: only-multiline,
functions: only-multiline,
imports: only-multiline,
objects: only-multiline,
}]
prefer-object-spread: error
no-buffer-constructor: error
no-mixed-operators:
Expand Down
2 changes: 1 addition & 1 deletion tools/build-addons.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async function buildAddon(dir) {
await execFile(process.execPath, [nodeGyp, 'rebuild', `--directory=${dir}`],
{
stdio: 'inherit',
env: { ...process.env, MAKEFLAGS: '-j1' }
env: { ...process.env, MAKEFLAGS: '-j1' },
});

// We buffer the output and print it out once the process is done in order
Expand Down
6 changes: 3 additions & 3 deletions tools/doc/addon-verify.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ tree.children.forEach((node) => {

await Promise.all(
Object.keys(addons).flatMap(
(header) => verifyFiles(addons[header].files, header)
(header) => verifyFiles(addons[header].files, header),
));

function verifyFiles(files, blockName) {
Expand Down Expand Up @@ -82,8 +82,8 @@ ${files[name].replace(
sources: files.map(({ name }) => name),
includes: ['../common.gypi'],
},
]
})
],
}),
});

const dirCreation = mkdir(dir);
Expand Down
4 changes: 2 additions & 2 deletions tools/doc/allhtml.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ all = all.slice(0, apiStart.index + apiStart[0].length)
'\n</head>',
buildCSSForFlavoredJS(new Set(Array.from(
apicontent.matchAll(/(?<=<pre class="with-)\d+(?=-chars">)/g),
(x) => Number(x[0])
))) + '\n</head>'
(x) => Number(x[0]),
))) + '\n</head>',
) +
apicontent +
all.slice(apiEnd);
Expand Down
4 changes: 2 additions & 2 deletions tools/doc/alljson.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const results = {
modules: [],
classes: [],
globals: [],
methods: []
methods: [],
};

// Identify files that should be skipped. As files are processed, they
Expand All @@ -33,7 +33,7 @@ for (const link of toc.match(/<a.*?>/g)) {
if (!jsonFiles.includes(json) || seen.has(json)) continue;
const data = JSON.parse(
fs.readFileSync(new URL(`./${json}`, source), 'utf8')
.replace(/<a href=\\"#/g, `<a href=\\"${href}#`)
.replace(/<a href=\\"#/g, `<a href=\\"${href}#`),
);

for (const property in data) {
Expand Down
2 changes: 1 addition & 1 deletion tools/doc/apilinks.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function execSync(command) {
try {
return child_process.execSync(
command,
{ stdio: ['ignore', null, 'ignore'] }
{ stdio: ['ignore', null, 'ignore'] },
).toString().trim();
} catch {
return '';
Expand Down
8 changes: 4 additions & 4 deletions tools/doc/deprecationCodes.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const testHeading = (headingNode, expectedDeprecationCode) => {
assert.strictEqual(
headingNode?.children[0]?.value.substring(0, 9),
`${expectedDeprecationCode}: `,
'Ill-formed or out-of-order deprecation code.'
'Ill-formed or out-of-order deprecation code.',
);
} catch (e) {
throw addMarkdownPathToErrorStack(e, headingNode);
Expand All @@ -39,7 +39,7 @@ const testYAMLComment = (commentNode) => {
assert.match(
commentNode?.value?.substring(0, 21),
/^<!-- YAML\r?\nchanges:\r?\n/,
'Missing or ill-formed YAML comment.'
'Missing or ill-formed YAML comment.',
);
} catch (e) {
throw addMarkdownPathToErrorStack(e, commentNode);
Expand All @@ -51,7 +51,7 @@ const testDeprecationType = (paragraphNode) => {
assert.strictEqual(
paragraphNode?.children[0]?.value?.substring(0, 6),
'Type: ',
'Missing deprecation type.'
'Missing deprecation type.',
);
} catch (e) {
throw addMarkdownPathToErrorStack(e, paragraphNode);
Expand All @@ -74,7 +74,7 @@ for (let i = 0; i < tree.children.length; i++) {
assert.strictEqual(
deprecationCodeAsText,
expectedDeprecationCode,
'Deprecation codes are not ordered correctly.'
'Deprecation codes are not ordered correctly.',
);
} catch (e) {
throw addMarkdownPathToErrorStack(e, node);
Expand Down
8 changes: 4 additions & 4 deletions tools/doc/html.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export function preprocessElements({ filename }) {
} else if (node.type === 'code') {
if (!node.lang) {
console.warn(
`No language set in ${filename}, line ${node.position.start.line}`
`No language set in ${filename}, line ${node.position.start.line}`,
);
}
const className = isJSFlavorSnippet(node) ?
Expand Down Expand Up @@ -302,7 +302,7 @@ export function preprocessElements({ filename }) {
(noLinking ? '' :
'<a href="documentation.html#stability-index">') +
`${prefix} ${number}${noLinking ? '' : '</a>'}`
.replace(/\n/g, ' ')
.replace(/\n/g, ' '),
});

// Remove prefix and number from text
Expand Down Expand Up @@ -408,7 +408,7 @@ export function buildToc({ filename, apilinks }) {

if (node.depth - depth > 1) {
throw new Error(
`Inappropriate heading level:\n${JSON.stringify(node)}`
`Inappropriate heading level:\n${JSON.stringify(node)}`,
);
}

Expand Down Expand Up @@ -543,7 +543,7 @@ function gtocPicker(id) {

// Highlight the current module and add a link to the index
const gtoc = gtocHTML.replace(
`class="nav-${id}"`, `class="nav-${id} active"`
`class="nav-${id}"`, `class="nav-${id} active"`,
).replace('</ul>', `
<li>
<a href="index.html">Index</a>
Expand Down
4 changes: 2 additions & 2 deletions tools/doc/json.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ function parseSignature(text, sig) {
throw new Error(
`Invalid param "${sigParam}"\n` +
` > ${JSON.stringify(listParam)}\n` +
` > ${text}`
` > ${text}`,
);
}
}
Expand All @@ -376,7 +376,7 @@ function parseListItem(item, file) {

current.textRaw = item.children.filter((node) => node.type !== 'list')
.map((node) => (
file.value.slice(node.position.start.offset, node.position.end.offset))
file.value.slice(node.position.start.offset, node.position.end.offset)),
)
.join('').replace(/\s+/g, ' ').replace(/<!--.*?-->/sg, '');
let text = current.textRaw;
Expand Down
2 changes: 1 addition & 1 deletion tools/doc/markdown.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function replaceLinks({ filename, linksMapper }) {
if (node.url) {
node.url = node.url.replace(
referenceToLocalMdFile,
(_, filename, hash) => `${filename}.html${hash || ''}`
(_, filename, hash) => `${filename}.html${hash || ''}`,
);
}
});
Expand Down
4 changes: 2 additions & 2 deletions tools/doc/type-parser.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const jsPrimitives = {
number: 'Number',
string: 'String',
symbol: 'Symbol',
undefined: 'Undefined'
undefined: 'Undefined',
};

const jsGlobalObjectsUrl = `${jsDocPrefix}Reference/Global_Objects/`;
Expand Down Expand Up @@ -301,7 +301,7 @@ export function toLink(typeInput) {
} else {
throw new Error(
`Unrecognized type: '${typeTextFull}'.\n` +
`Please, edit the type or update '${import.meta.url}'.`
`Please, edit the type or update '${import.meta.url}'.`,
);
}
} else {
Expand Down
4 changes: 2 additions & 2 deletions tools/eslint-rules/alphabetize-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = {
const message = [prefix, prev, opStr, curr].join('');
context.report({ node, message });
}
}
},
};
}
},
};
8 changes: 4 additions & 4 deletions tools/eslint-rules/async-iife-no-unused-result.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const message =

module.exports = {
meta: {
fixable: 'code'
fixable: 'code',
},
create: function(context) {
let hasCommonModule = false;
Expand All @@ -31,10 +31,10 @@ module.exports = {
fix: (fixer) => {
if (hasCommonModule)
return fixer.insertTextAfter(node, '.then(common.mustCall())');
}
},
});
}
}
},
};
}
},
};
6 changes: 3 additions & 3 deletions tools/eslint-rules/avoid-prototype-pollution.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function createUnsafeStringMethodReport(context, name, lookedUpProperty) {
node,
message: `${name} looks up the ${lookedUpProperty} property on the first argument`,
});
}
},
};
}

Expand All @@ -98,7 +98,7 @@ function createUnsafeStringMethodOnRegexReport(context, name, lookedUpProperty)
node,
message: `${name} looks up the ${lookedUpProperty} property of the passed regex, use ${safePrimordialName} directly`,
});
}
},
};
}

Expand Down Expand Up @@ -155,7 +155,7 @@ module.exports = {
fixer.replaceTextRange(testRange, 'Exec'),
fixer.insertTextAfter(node, ' !== null'),
];
}
},
}],
});
},
Expand Down
10 changes: 5 additions & 5 deletions tools/eslint-rules/crypto-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ module.exports = {
if (beforeAllChecks) {
context.report({
node: requireNode,
message: msg
message: msg,
});
}
});
Expand Down Expand Up @@ -106,10 +106,10 @@ module.exports = {
commonModuleNode,
'\nif (!common.hasCrypto) {' +
' common.skip("missing crypto");' +
'}'
'}',
);
}
}
},
});
});
}
Expand All @@ -118,7 +118,7 @@ module.exports = {
'CallExpression': (node) => testCryptoUsage(node),
'IfStatement:exit': (node) => testIfStatement(node),
'MemberExpression:exit': (node) => testMemberExpression(node),
'Program:exit': () => reportIfMissingCheck()
'Program:exit': () => reportIfMissingCheck(),
};
}
},
};
4 changes: 2 additions & 2 deletions tools/eslint-rules/documented-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.exports = {
`doc/api/errors.md does not have an anchor for "${code}"`;
context.report({ node, message });
}
}
},
};
}
},
};
8 changes: 4 additions & 4 deletions tools/eslint-rules/eslint-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ module.exports = {
if (commonModuleNode) {
return fixer.insertTextAfter(
commonModuleNode,
'\ncommon.skipIfEslintMissing();'
'\ncommon.skipIfEslintMissing();',
);
}
}
},
});
});
}
Expand All @@ -59,7 +59,7 @@ module.exports = {
return {
'CallExpression': (node) => testEslintUsage(context, node),
'MemberExpression': (node) => checkMemberExpression(context, node),
'Program:exit': () => reportIfMissing(context)
'Program:exit': () => reportIfMissing(context),
};
}
},
};
Loading

0 comments on commit 070a5f7

Please sign in to comment.