Skip to content

Commit

Permalink
feat: add in recommended unicorn rules
Browse files Browse the repository at this point in the history
This was probably an intentional omission, but I think it's better to manually disable these rules.
  • Loading branch information
lishaduck committed Jul 16, 2024
1 parent bed9e88 commit 71f865e
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 56 deletions.
17 changes: 7 additions & 10 deletions apps/docs-website/docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import { version } from 'eslint-config-sheriff/package.json';
import { themes } from 'prism-react-renderer';
// eslint-disable-next-line @typescript-eslint/naming-convention
import type * as Preset from '@docusaurus/preset-classic';
import remarkPluginNpm2Yarn from '@docusaurus/remark-plugin-npm2yarn'; // eslint-disable-line import/no-named-as-default
import type { Config } from '@docusaurus/types';

const lightCodeTheme = themes.github;
const darkCodeTheme = themes.dracula;

const currentYear = new Date().getFullYear();

const config: Config = {
const config = {
title: 'Sheriff',
tagline:
'A comprehensive and opinionated Typescript-first ESLint configuration.',
Expand Down Expand Up @@ -42,19 +43,15 @@ const config: Config = {
'classic',
{
docs: {
sidebarPath: require.resolve('./sidebars.js'),
remarkPlugins: [
[require('@docusaurus/remark-plugin-npm2yarn'), { sync: true }],
],
sidebarPath: import.meta.resolve('./sidebars.js'),
remarkPlugins: [[remarkPluginNpm2Yarn, { sync: true }]],
},
blog: {
showReadingTime: true,
remarkPlugins: [
[require('@docusaurus/remark-plugin-npm2yarn'), { sync: true }],
],
remarkPlugins: [[remarkPluginNpm2Yarn, { sync: true }]],
},
theme: {
customCss: require.resolve('./src/css/custom.css'),
customCss: import.meta.resolve('./src/css/custom.css'),
},
} satisfies Preset.Options,
],
Expand Down Expand Up @@ -143,6 +140,6 @@ const config: Config = {
headingIds: true,
},
},
};
} satisfies Config;

export default config;
4 changes: 2 additions & 2 deletions apps/sheriff-webservices/src/generateRulesDataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,11 @@ const getCompiledConfig = (
return atomRemappedRecords;
});

const declaredRules = compiledConfig.map((rule) => rule.ruleName);
const declaredRules = new Set(compiledConfig.map((rule) => rule.ruleName));

if (allRulesRaw) {
for (const [ruleName, ruleOptions] of Object.entries(allRulesRaw)) {
if (!declaredRules.includes(ruleName)) {
if (!declaredRules.has(ruleName)) {
const parentPluginName = getParentPluginName(ruleName);

const ruleRecord: Entry = {
Expand Down
2 changes: 1 addition & 1 deletion apps/sheriff-webservices/src/getAllRules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import fp from 'eslint-plugin-fp';
import fsecond from 'eslint-plugin-fsecond';
import pluginImport from 'eslint-plugin-import';
import jest from 'eslint-plugin-jest';
import jsdoc from 'eslint-plugin-jsdoc'; // eslint-disable-line
import jsdoc from 'eslint-plugin-jsdoc'; // eslint-disable-line import/no-named-as-default
import reactAccessibility from 'eslint-plugin-jsx-a11y';
import lodashPlugin from 'eslint-plugin-lodash-f';
import playwright from 'eslint-plugin-playwright';
Expand Down
4 changes: 2 additions & 2 deletions packages/create-sheriff-config/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const { argv } = yargs(hideBin(process.argv)).option('filter', {
description: 'Filter for specific workspace',
});

// eslint-disable-next-line
// eslint-disable-next-line func-style
async function main() {
const commandArguments = await argv;
const isWorkspace = Boolean(commandArguments.filter);
Expand All @@ -36,5 +36,5 @@ async function main() {
consola.info("You're all set!");
}

// eslint-disable-next-line
// eslint-disable-next-line unicorn/prefer-top-level-await, @typescript-eslint/no-floating-promises
main();
5 changes: 4 additions & 1 deletion packages/eslint-config-sheriff/src/getBaseConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ export const getBaseConfig = (
name: 'Base Sheriff Config (Unicorn)',
files: [supportedFileTypes],
plugins: { unicorn },
rules: unicornHandPickedRules,
rules: {
...unicorn.configs.recommended.rules,
...unicornHandPickedRules,
},
},
{
name: 'Base Sheriff Config (SonarJS)',
Expand Down
8 changes: 7 additions & 1 deletion packages/eslint-config-sheriff/src/handledModules.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ declare module '@regru/eslint-plugin-prefer-early-return' {
declare module 'eslint-plugin-unicorn' {
import type { TSESLint } from '@typescript-eslint/utils';

declare const defaultExport: TSESLint.FlatConfig.Plugin;
declare const defaultExport: TSESLint.FlatConfig.Plugin & {
configs: {
recommended: {
rules: TSESLint.FlatConfig.Rules;
};
};
};

export default defaultExport;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,46 +1,11 @@
import type { TSESLint } from '@typescript-eslint/utils';

export const unicornHandPickedRules = {
'unicorn/better-regex': 2,
'unicorn/explicit-length-check': 2,
'unicorn/consistent-function-scoping': 2,
'unicorn/prefer-default-parameters': 2,
'unicorn/no-array-push-push': 2,
'unicorn/prefer-array-index-of': 2,
'unicorn/prefer-array-flat-map': 2,
'unicorn/prefer-array-some': 2,
'unicorn/prefer-array-find': 2,
'unicorn/prefer-array-flat': 2,
'unicorn/prefer-includes': 2,
'unicorn/prefer-top-level-await': 2,
'unicorn/prefer-spread': 2,
'unicorn/no-useless-spread': 2,
'unicorn/no-useless-fallback-in-spread': 2,
'unicorn/no-for-loop': 2,
'unicorn/prefer-set-size': 2,
'unicorn/prefer-type-error': 2,
'unicorn/prefer-object-from-entries': 2,
'unicorn/no-instanceof-array': 2,
'unicorn/prefer-native-coercion-functions': 2,
'unicorn/prefer-logical-operator-over-ternary': 2,
'unicorn/prefer-event-target': 2,
'unicorn/no-await-expression-member': 2,
'unicorn/no-new-array': 2,
'unicorn/throw-new-error': 2,
'unicorn/no-array-reduce': 2,
'unicorn/no-useless-length-check': 2,
'unicorn/prefer-prototype-methods': 2,
'unicorn/prefer-date-now': 2,
'unicorn/prefer-node-protocol': 2,
'unicorn/prefer-export-from': [2, { ignoreUsedVariables: true }],
'unicorn/no-new-buffer': 2,
'unicorn/prefer-query-selector': 2,
'unicorn/prefer-string-replace-all': 2,
'unicorn/prefer-switch': [2, { emptyDefaultCase: 'do-nothing-comment' }],
'unicorn/switch-case-braces': 2,
'unicorn/catch-error-name': 2,
'unicorn/consistent-destructuring': 2,
'unicorn/prefer-string-slice': 2,
'unicorn/no-await-in-promise-methods': 2,
'unicorn/no-single-promise-in-promise-methods': 2,
'unicorn/filename-case': 0, // This rule is project-specific.
'unicorn/no-null': 0, // This rule is too strict.
'unicorn/no-process-exit': 0, // This rule is wrong in the context of a CLI.
'unicorn/prevent-abbreviations': 0, // This rule is too strict.
} as const satisfies TSESLint.FlatConfig.Rules;

0 comments on commit 71f865e

Please sign in to comment.