Skip to content

Commit

Permalink
chore: lint eslint-config-sheriff with eslint-config-sheriff
Browse files Browse the repository at this point in the history
  • Loading branch information
lishaduck committed Jul 12, 2024
1 parent 25a4855 commit 1351a39
Show file tree
Hide file tree
Showing 30 changed files with 348 additions and 85 deletions.
25 changes: 25 additions & 0 deletions packages/eslint-config-sheriff/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// @ts-check
import sheriff from 'eslint-config-sheriff';
import { defineFlatConfig } from 'eslint-define-config';

const sheriffOptions = {
react: false,
next: false,
astro: false,
lodash: false,
playwright: false,
jest: false,
vitest: false,
};

const sheriffRules = sheriff(sheriffOptions);

export default defineFlatConfig([
...sheriffRules,
{
files: ['**.ts'],
rules: {
'fsecond/prefer-destructured-optionals': 'off',
},
},
]);
1 change: 1 addition & 0 deletions packages/eslint-config-sheriff/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"clean": "rm -rf .turbo dist",
"build": "tsup",
"typecheck": "tsc --noEmit",
"lint": "eslint . --max-warnings=0 --cache --cache-location=node_modules/.cache/.eslintcache",
"publint": "publint",
"typesync": "typesync --dry=fail",
"are-the-types-wrong": "attw --pack ."
Expand Down
5 changes: 3 additions & 2 deletions packages/eslint-config-sheriff/src/getAstroConfig.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import astro from 'eslint-plugin-astro';
import astroParser from 'astro-eslint-parser';
import astro from 'eslint-plugin-astro';
import type { TSESLint } from '@typescript-eslint/utils';

export const getAstroConfig = (
hasReact: boolean,
customTSConfigPath: string | string[] | undefined,
) => {
): TSESLint.FlatConfig.Config => {
return {
files: ['**/*.astro'],
plugins: {
Expand Down
39 changes: 22 additions & 17 deletions packages/eslint-config-sheriff/src/getBaseConfig.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,39 @@
import eslintRecommended from '@eslint/js';
import tseslint from 'typescript-eslint';
import unicorn from 'eslint-plugin-unicorn';
import sonarjs from 'eslint-plugin-sonarjs';
import jsdoc from 'eslint-plugin-jsdoc';
import arrowReturnStyle from 'eslint-plugin-arrow-return-style';
import fp from 'eslint-plugin-fp';
import fsecond from 'eslint-plugin-fsecond';
import pluginImport from 'eslint-plugin-import';
import jsdoc from 'eslint-plugin-jsdoc';
import simpleImportSort from 'eslint-plugin-simple-import-sort';
import fp from 'eslint-plugin-fp';
import preferEarlyReturn from '@regru/eslint-plugin-prefer-early-return';
import tsdoc from 'eslint-plugin-tsdoc';
import sonarjs from 'eslint-plugin-sonarjs';
import storybook from 'eslint-plugin-storybook';
import fsecond from 'eslint-plugin-fsecond';
import arrowReturnStyle from 'eslint-plugin-arrow-return-style';
import tsdoc from 'eslint-plugin-tsdoc';
import unicorn from 'eslint-plugin-unicorn';
import tseslint from 'typescript-eslint';
import eslintRecommended from '@eslint/js';
import preferEarlyReturn from '@regru/eslint-plugin-prefer-early-return';
import { allJsExtensions, supportedFileTypes } from '@sherifforg/constants';
import type { SheriffSettings } from '@sherifforg/types';
import stylistic from '@stylistic/eslint-plugin';
import { supportedFileTypes, allJsExtensions } from '@sherifforg/constants';
import { SheriffSettings } from '@sherifforg/types';
import type { FlatConfig } from '@typescript-eslint/utils/ts-eslint';
import { getAstroConfig } from './getAstroConfig';
import { fpHandPickedRules } from './handpickedRules/fpHandPickedRules';
import { getTsNamingConventionRule } from './utils/getTsNamingConventionRule';
import { getBaseEslintHandPickedRules } from './handpickedRules/getBaseEslintHandPickedRules';
import { importHandPickedRules } from './handpickedRules/importHandPickedRules';
import { jsdocHandPickedRules } from './handpickedRules/jsdocHandPickedRules';
import { sonarjsHandPickedRules } from './handpickedRules/sonarjsHandPickedRules';
import { stylisticHandPickedRules } from './handpickedRules/stylisticHandPickedRules';
import { typescriptHandPickedRules } from './handpickedRules/typescriptHandPickedRules';
import { unicornHandPickedRules } from './handpickedRules/unicornHandPickedRules';
import { getBaseEslintHandPickedRules } from './handpickedRules/getBaseEslintHandPickedRules';
import { getLanguageOptionsTypescript } from './utils/getLanguageOptionsTypescript';
import { getTsNamingConventionRule } from './utils/getTsNamingConventionRule';

export const getBaseConfig = (userConfigChoices: SheriffSettings) => {
export const getBaseConfig = (
userConfigChoices: SheriffSettings,
): FlatConfig.ConfigArray => {
const customTSConfigPath = userConfigChoices.pathsOverrides?.tsconfigLocation;
const { noRestrictedSyntaxOverride } = userConfigChoices;
const hasReact = Boolean(userConfigChoices.react);
// eslint-disable-next-line @typescript-eslint/naming-convention
const { noRestrictedSyntaxOverride, react } = userConfigChoices;
const hasReact = Boolean(react);

return tseslint.config(
{
Expand Down Expand Up @@ -99,6 +103,7 @@ export const getBaseConfig = (userConfigChoices: SheriffSettings) => {
files: [supportedFileTypes],
plugins: { sonarjs },
rules: {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- Still has eslintrc types.
...sonarjs.configs.recommended.rules,
...sonarjsHandPickedRules,
},
Expand Down
26 changes: 12 additions & 14 deletions packages/eslint-config-sheriff/src/getExportableConfig.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
import eslintConfigPrettier from 'eslint-config-prettier';
import getGitignorePatterns from 'eslint-config-flat-gitignore';
import lodash from 'lodash';
import eslintConfigPrettier from 'eslint-config-prettier';
import type { FlatESLintConfig } from 'eslint-define-config';
import { SheriffSettings } from '@sherifforg/types';
import lodash from 'lodash';
import { ignores } from '@sherifforg/constants';
import { getReactConfig } from './getReactConfig';
import type { SheriffSettings } from '@sherifforg/types';
import type { TSESLint } from '@typescript-eslint/utils';
import { getBaseConfig } from './getBaseConfig';
import { nextjsConfig } from './nextjsConfig';
import { playwrightConfig } from './playwrightConfig';
import { lodashConfig } from './lodashConfig';
import { getJestConfig } from './getJestConfig';
import { getReactConfig } from './getReactConfig';
import { getVitestConfig } from './getVitestConfig';
import { lodashConfig } from './lodashConfig';
import { nextjsConfig } from './nextjsConfig';
import { playwrightConfig } from './playwrightConfig';
import { prettierOverrides } from './prettierOverrides';
import { type TSESLint } from '@typescript-eslint/utils';

export const getExportableConfig = (
userConfigChoices: SheriffSettings,
areAllRulesForced?: boolean,
): FlatESLintConfig[] => {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- ESLint isn't TypeScript first, so this is just in case.
if (!userConfigChoices) {
throw new Error('No settings provided.');
}
Expand Down Expand Up @@ -52,7 +53,6 @@ export const getExportableConfig = (

if (userConfigChoices.vitest) {
exportableConfig.push(
//@ts-expect-error
getVitestConfig(userConfigChoices.pathsOverrides?.tests),
);
}
Expand All @@ -69,9 +69,7 @@ export const getExportableConfig = (
exportableConfig.push(playwrightConfig);
}

exportableConfig.push(eslintConfigPrettier);
//@ts-expect-error
exportableConfig.push(prettierOverrides);
exportableConfig.push(eslintConfigPrettier, prettierOverrides);

if (userConfigChoices.files) {
const allowedPatterns = userConfigChoices.files.map(
Expand All @@ -93,13 +91,13 @@ export const getExportableConfig = (
const hasIgnoresRecommended = lodash.isBoolean(
userConfigChoices.ignores?.recommended,
)
? userConfigChoices.ignores?.recommended
? userConfigChoices.ignores.recommended
: true;

const hasIgnoresInheritedFromGitignore = lodash.isBoolean(
userConfigChoices.ignores?.inheritedFromGitignore,
)
? userConfigChoices.ignores?.inheritedFromGitignore
? userConfigChoices.ignores.inheritedFromGitignore
: true;

exportableConfig.push({
Expand Down
3 changes: 2 additions & 1 deletion packages/eslint-config-sheriff/src/getJestConfig.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import jest from 'eslint-plugin-jest';
import { allJsExtensions } from '@sherifforg/constants';
import type { FlatConfig } from '@typescript-eslint/utils/ts-eslint';
import { jestHandPickedRules } from './handpickedRules/jestHandPickedRules';

export const getJestConfig = (pathsOverrides?: string[]) => {
export const getJestConfig = (pathsOverrides?: string[]): FlatConfig.Config => {
return {
files: pathsOverrides ?? [
`**/*.{test,spec}.{${allJsExtensions}}`,
Expand Down
13 changes: 8 additions & 5 deletions packages/eslint-config-sheriff/src/getReactConfig.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
import reactRecommended from 'eslint-plugin-react/configs/recommended.js';
import jsxRuntime from 'eslint-plugin-react/configs/jsx-runtime.js';
import fsecond from 'eslint-plugin-fsecond';
import reactAccessibility from 'eslint-plugin-jsx-a11y';
import jsxRuntime from 'eslint-plugin-react/configs/jsx-runtime.js';
import reactRecommended from 'eslint-plugin-react/configs/recommended.js';
import reactHooks from 'eslint-plugin-react-hooks';
import reactRefresh from 'eslint-plugin-react-refresh';
import fsecond from 'eslint-plugin-fsecond';
import rel1cxReact from '@eslint-react/eslint-plugin';
import {
allJsExtensions,
allJsxExtensions,
supportedFileTypes,
} from '@sherifforg/constants';
import { getTsNamingConventionRule } from './utils/getTsNamingConventionRule';
import type { TSESLint } from '@typescript-eslint/utils';
import { reactHandPickedRules } from './handpickedRules/reactHandPickedRules';
import { getLanguageOptionsTypescriptReact } from './utils/getLanguageOptionsTypescriptReact';
import { getTsNamingConventionRule } from './utils/getTsNamingConventionRule';

export const getReactConfig = (customTSConfigPath?: string | string[]) => {
export const getReactConfig = (
customTSConfigPath?: string | string[],
): TSESLint.FlatConfig.ConfigArray => {
return [
{
files: [supportedFileTypes],
Expand Down
5 changes: 4 additions & 1 deletion packages/eslint-config-sheriff/src/getVitestConfig.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import vitest from 'eslint-plugin-vitest';
import { allJsExtensions } from '@sherifforg/constants';
import type { TSESLint } from '@typescript-eslint/utils';
import { vitestHandPickedRules } from './handpickedRules/vitestHandPickedRules';

export const getVitestConfig = (pathsOverrides?: string[]) => {
export const getVitestConfig = (
pathsOverrides?: string[],
): TSESLint.FlatConfig.Config => {
return {
files: pathsOverrides ?? [
`**/*.{test,spec}.{${allJsExtensions}}`,
Expand Down
Loading

0 comments on commit 1351a39

Please sign in to comment.