Skip to content
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

Tweak unicorn linting #584

Merged
merged 1 commit into from
Dec 9, 2024
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
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
Loading