Skip to content

Commit 3c0cb1a

Browse files
authored
Tweak unicorn linting (#584)
1 parent 4c527d5 commit 3c0cb1a

File tree

6 files changed

+13
-11
lines changed

6 files changed

+13
-11
lines changed

eslint.config.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,12 @@ export default tseslint.config(
3333
],
3434

3535
// unicorn rules:
36-
'require-unicode-regexp': 'error',
3736
'unicorn/expiring-todo-comments': 'off',
3837
'unicorn/import-style': 'off',
3938
'unicorn/no-anonymous-default-export': 'off',
4039
'unicorn/no-array-reduce': 'off',
4140
'unicorn/no-nested-ternary': 'off',
4241
'unicorn/no-useless-undefined': 'off', // We use a lot of `return undefined` to satisfy the `consistent-return` rule.
43-
'unicorn/prefer-at': 'off',
44-
'unicorn/prefer-string-raw': 'off',
45-
'unicorn/prefer-string-replace-all': 'off',
4642
'unicorn/prevent-abbreviations': 'off',
4743

4844
// typescript-eslint rules:
@@ -112,6 +108,7 @@ export default tseslint.config(
112108
radix: 'error',
113109
'require-atomic-updates': 'error',
114110
'require-await': 'error',
111+
'require-unicode-regexp': 'error',
115112
'spaced-comment': ['error', 'always', { markers: ['*', '!'] }],
116113
'sort-vars': 'error',
117114
yoda: 'error',

lib/markdown.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ export function expectContentOrFail(
9393
// in case escaping is needed where the content is referenced.
9494
const hasContent =
9595
contents.includes(content) ||
96-
contents.includes(content.replace(/"/gu, '\\"')) ||
97-
contents.includes(content.replace(/'/gu, "\\'"));
96+
contents.includes(content.replaceAll('"', String.raw`\"`)) ||
97+
contents.includes(content.replaceAll("'", String.raw`\'`));
9898
if (hasContent !== expected) {
9999
console.error(
100100
`${docName} should ${

lib/rule-link.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export function replaceRulePlaceholder(
1414
if (typeof pathOrUrl === 'function') {
1515
return pathOrUrl(ruleName);
1616
}
17-
return pathOrUrl.replace(/\{name\}/gu, ruleName);
17+
return pathOrUrl.replaceAll('{name}', ruleName);
1818
}
1919

2020
/**

lib/rule-list.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,11 @@ function getRulesAndHeadersForSplit(
365365
// Turn ruleListSplit into a title.
366366
// E.g. meta.docs.requiresTypeChecking to "Requires Type Checking".
367367
const ruleListSplitParts = ruleListSplitItem.split('.');
368-
const ruleListSplitFinalPart =
369-
ruleListSplitParts[ruleListSplitParts.length - 1];
368+
const ruleListSplitFinalPart = ruleListSplitParts.at(-1);
369+
/* istanbul ignore next -- this shouldn't happen */
370+
if (!ruleListSplitFinalPart) {
371+
throw new Error(`Invalid ruleListSplit value "${ruleListSplitItem}".`);
372+
}
370373
const ruleListSplitTitle = noCase(ruleListSplitFinalPart, {
371374
transform: (str) => capitalizeOnlyFirstLetter(str),
372375
});

lib/string.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ export function capitalizeOnlyFirstLetter(str: string) {
2222
}
2323

2424
function sanitizeMarkdownTableCell(text: string): string {
25-
return text.replace(/\|/gu, '\\|').replace(new RegExp(EOL, 'gu'), '<br/>');
25+
return text
26+
.replaceAll('|', String.raw`\|`)
27+
.replaceAll(new RegExp(EOL, 'gu'), '<br/>');
2628
}
2729

2830
export function sanitizeMarkdownTable(

test/lib/generate/option-postprocess-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ describe('generate (postprocess option)', function () {
4949
[
5050
content,
5151
'',
52-
`Located at ${relative('.', path).replace(/\\/gu, '/')}`, // Always use forward slashes in the path so the snapshot is right even when testing on Windows.
52+
`Located at ${relative('.', path).replaceAll('\\', '/')}`, // Always use forward slashes in the path so the snapshot is right even when testing on Windows.
5353
].join('\n'),
5454
});
5555
expect(readFileSync('README.md', 'utf8')).toMatchSnapshot();

0 commit comments

Comments
 (0)