Skip to content

Commit

Permalink
Tweak unicorn linting (#584)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmish authored Dec 9, 2024
1 parent 4c527d5 commit 3c0cb1a
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 11 deletions.
5 changes: 1 addition & 4 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,12 @@ export default tseslint.config(
],

// unicorn rules:
'require-unicode-regexp': 'error',
'unicorn/expiring-todo-comments': 'off',
'unicorn/import-style': 'off',
'unicorn/no-anonymous-default-export': 'off',
'unicorn/no-array-reduce': 'off',
'unicorn/no-nested-ternary': 'off',
'unicorn/no-useless-undefined': 'off', // We use a lot of `return undefined` to satisfy the `consistent-return` rule.
'unicorn/prefer-at': 'off',
'unicorn/prefer-string-raw': 'off',
'unicorn/prefer-string-replace-all': 'off',
'unicorn/prevent-abbreviations': 'off',

// typescript-eslint rules:
Expand Down Expand Up @@ -112,6 +108,7 @@ export default tseslint.config(
radix: 'error',
'require-atomic-updates': 'error',
'require-await': 'error',
'require-unicode-regexp': 'error',
'spaced-comment': ['error', 'always', { markers: ['*', '!'] }],
'sort-vars': 'error',
yoda: 'error',
Expand Down
4 changes: 2 additions & 2 deletions lib/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ export function expectContentOrFail(
// in case escaping is needed where the content is referenced.
const hasContent =
contents.includes(content) ||
contents.includes(content.replace(/"/gu, '\\"')) ||
contents.includes(content.replace(/'/gu, "\\'"));
contents.includes(content.replaceAll('"', String.raw`\"`)) ||
contents.includes(content.replaceAll("'", String.raw`\'`));
if (hasContent !== expected) {
console.error(
`${docName} should ${
Expand Down
2 changes: 1 addition & 1 deletion lib/rule-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function replaceRulePlaceholder(
if (typeof pathOrUrl === 'function') {
return pathOrUrl(ruleName);
}
return pathOrUrl.replace(/\{name\}/gu, ruleName);
return pathOrUrl.replaceAll('{name}', ruleName);
}

/**
Expand Down
7 changes: 5 additions & 2 deletions lib/rule-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,11 @@ function getRulesAndHeadersForSplit(
// Turn ruleListSplit into a title.
// E.g. meta.docs.requiresTypeChecking to "Requires Type Checking".
const ruleListSplitParts = ruleListSplitItem.split('.');
const ruleListSplitFinalPart =
ruleListSplitParts[ruleListSplitParts.length - 1];
const ruleListSplitFinalPart = ruleListSplitParts.at(-1);
/* istanbul ignore next -- this shouldn't happen */
if (!ruleListSplitFinalPart) {
throw new Error(`Invalid ruleListSplit value "${ruleListSplitItem}".`);
}
const ruleListSplitTitle = noCase(ruleListSplitFinalPart, {
transform: (str) => capitalizeOnlyFirstLetter(str),
});
Expand Down
4 changes: 3 additions & 1 deletion lib/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ export function capitalizeOnlyFirstLetter(str: string) {
}

function sanitizeMarkdownTableCell(text: string): string {
return text.replace(/\|/gu, '\\|').replace(new RegExp(EOL, 'gu'), '<br/>');
return text
.replaceAll('|', String.raw`\|`)
.replaceAll(new RegExp(EOL, 'gu'), '<br/>');
}

export function sanitizeMarkdownTable(
Expand Down
2 changes: 1 addition & 1 deletion test/lib/generate/option-postprocess-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('generate (postprocess option)', function () {
[
content,
'',
`Located at ${relative('.', path).replace(/\\/gu, '/')}`, // Always use forward slashes in the path so the snapshot is right even when testing on Windows.
`Located at ${relative('.', path).replaceAll('\\', '/')}`, // Always use forward slashes in the path so the snapshot is right even when testing on Windows.
].join('\n'),
});
expect(readFileSync('README.md', 'utf8')).toMatchSnapshot();
Expand Down

0 comments on commit 3c0cb1a

Please sign in to comment.