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

AndreaPontrandolfo/issue236 #326

Merged
merged 2 commits into from
Dec 21, 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
7 changes: 7 additions & 0 deletions .changeset/angry-jobs-flash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'eslint-config-sheriff': patch
'@sherifforg/create-config': patch
---

feat(internal): linting core package with itself
Fixes #236
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"eslint.workingDirectories": [
"./packages/sheriff-create-config",
"./packages/eslint-config-sheriff",
"./packages/sheriff-cli",
"./packages/sheriff-utils",
"./packages/sheriff-types",
"./apps/docs-website",
"./apps/sheriff-webservices",
"./apps/config-validation-playground"
Expand All @@ -17,6 +17,9 @@
"markdown",
"astro"
],
"eslint.options": {
"flags": ["unstable_ts_config"]
},
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit",
"source.organizeImports": "never"
Expand Down
2 changes: 1 addition & 1 deletion apps/config-validation-playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@types/node": "^22.9.0",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.2.15",
"eslint": "^9.14.0",
"eslint": "^9.17.0",
"eslint-config-sheriff": "workspace:*",
"eslint-define-config": "^2.1.0",
"tsconfig": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion apps/docs-website/docs/requirements/hard-requirements.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ description: The bare minimum

# Hard requirements

- [Node >=18.18](https://nodejs.org/en/)
- [Node >=20.10](https://nodejs.org/en/)
- [ESLint >=9.0.0](https://eslint.org/)
- [Typescript >= 5.0.0](https://www.typescriptlang.org/)
2 changes: 1 addition & 1 deletion apps/docs-website/docs/requirements/recommendations.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: You probably need this too

# Recommendations

- [Node >=20](https://nodejs.org/en/)
- [Node >=22](https://nodejs.org/en/)
- [VScode](https://code.visualstudio.com/)
- [VScode eslint extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint)
- [VScode prettier extension](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode)
Expand Down
4 changes: 2 additions & 2 deletions apps/docs-website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"write-translations": "docusaurus write-translations",
"write-heading-ids": "docusaurus write-heading-ids",
"typecheck": "tsc --noEmit",
"lint": "eslint . --max-warnings=0",
"lint": "eslint --max-warnings=0",
"typesync": "typesync --dry=fail",
"clean": "pnpm clear && rm -rf .turbo dist node_modules/.cache"
},
Expand Down Expand Up @@ -45,7 +45,7 @@
"@types/node": "^22.9.0",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.2.15",
"eslint": "^9.14.0",
"eslint": "^9.17.0",
"eslint-config-sheriff": "workspace:*",
"eslint-define-config": "^2.1.0",
"eslint-plugin-mdx": "^3.1.5",
Expand Down
7 changes: 5 additions & 2 deletions apps/docs-website/src/components/RulesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ const columns = [
}),
columnHelper.accessor('ruleOptions', {
header: 'Options',
cell: (info) =>
isEmpty(info.getValue()) ? 'No options' : JSON.stringify(info.getValue()),
cell: (info) => {
return isEmpty(info.getValue())
? 'No options'
: JSON.stringify(info.getValue());
},
}),
columnHelper.accessor('docs', {
header: 'Docs',
Expand Down
6 changes: 3 additions & 3 deletions apps/sheriff-webservices/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"start": "tsx watch ./src/index.ts",
"build": "tsc",
"typecheck": "tsc --noEmit",
"lint": "eslint . --max-warnings=0",
"lint": "eslint --max-warnings=0",
"typesync": "typesync --dry=fail",
"serve": "node ./dist/index.js",
"clean": "rm -rf .turbo dist node_modules/.cache"
Expand All @@ -25,13 +25,13 @@
},
"dependencies": {
"@eslint-react/eslint-plugin": "^1.10.1",
"@eslint/js": "^9.14.0",
"@eslint/js": "^9.17.0",
"@hono/node-server": "^1.12.0",
"@next/eslint-plugin-next": "^13.2.3",
"@regru/eslint-plugin-prefer-early-return": "^1.0.0",
"@stylistic/eslint-plugin": "^2.6.4",
"@vitest/eslint-plugin": "^1.0.3",
"eslint": "^9.14.0",
"eslint": "^9.17.0",
"eslint-config-sheriff": "workspace:*",
"eslint-plugin-arrow-return-style": "^1.3.0",
"eslint-plugin-astro": "^1.2.3",
Expand Down
6 changes: 5 additions & 1 deletion apps/sheriff-webservices/src/getAllRules.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-unsafe-argument */
import type { ESLint } from 'eslint';
import arrowReturnStyle from 'eslint-plugin-arrow-return-style';
import astro from 'eslint-plugin-astro';
Expand Down Expand Up @@ -43,9 +44,11 @@ export const getAllRules = (
) => Record<string, RuleOptions>,
): BarebonesConfigAtom['rules'] => {
const reactRulesCatalog = {
// @ts-expect-error
...prependRulesWithPluginName(react.rules, 'react'),
...prependRulesWithPluginName(reactAccessibility.rules, 'jsx-a11y'),
...prependRulesWithPluginName(reactHooks.rules, 'react-hooks'),
// @ts-expect-error
...prependRulesWithPluginName(reactRefresh.rules, 'react-refresh'),
...prependRulesWithPluginName(
(rel1cxReact as unknown as Plugin).rules,
Expand Down Expand Up @@ -86,7 +89,8 @@ export const getAllRules = (
? prependRulesWithPluginName(nextjs.rules, '@next/next')
: {}),
...(settings.playwright
? prependRulesWithPluginName(playwright.rules, 'playwright')
? // @ts-expect-error
prependRulesWithPluginName(playwright.rules, 'playwright')
: {}),
...(settings.lodash
? prependRulesWithPluginName(lodashPlugin.rules, 'lodash-f')
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"turbo": "^2.2.3",
"typesync": "0.13.0"
},
"packageManager": "pnpm@9.10.0",
"packageManager": "pnpm@9.15.1",
"engines": {
"node": ">=20.10.0"
},
Expand Down
30 changes: 30 additions & 0 deletions packages/eslint-config-sheriff/eslint.config.js
AndreaPontrandolfo marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { sheriff } from 'eslint-config-sheriff';
import { defineFlatConfig } from 'eslint-define-config';

const sheriffOptions = {
react: false,
next: false,
lodash: true,
remeda: false,
AndreaPontrandolfo marked this conversation as resolved.
Show resolved Hide resolved
astro: false,
playwright: false,
jest: false,
vitest: false,
};

export default defineFlatConfig([
...sheriff(sheriffOptions),
{
rules: {
'fsecond/prefer-destructured-optionals': 0,
'@typescript-eslint/no-unsafe-return': 0,
'@typescript-eslint/no-unsafe-member-access': 0,
'@typescript-eslint/no-unsafe-argument': 0,
'sonarjs/no-duplicate-string': 0,
'lodash-f/import-scope': 0,
},
},
{
ignores: ['tsup.config.js'],
},
AndreaPontrandolfo marked this conversation as resolved.
Show resolved Hide resolved
]);
7 changes: 4 additions & 3 deletions packages/eslint-config-sheriff/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@
"build": "tsup && pnpm re-bundle-types",
"build-watch": "tsup && pnpm re-bundle-types",
"typecheck": "tsc --noEmit",
"lint": "eslint src --max-warnings=0",
"publint": "publint",
"typesync": "typesync --dry=fail"
},
"dependencies": {
"@eslint-react/eslint-plugin": "^1.10.1",
"@eslint/compat": "^1.1.1",
"@eslint/js": "^9.14.0",
"@eslint/compat": "^1.2.4",
"@eslint/js": "^9.17.0",
"@next/eslint-plugin-next": "^13.2.3",
"@regru/eslint-plugin-prefer-early-return": "^1.0.0",
"@stylistic/eslint-plugin": "^2.6.4",
Expand Down Expand Up @@ -104,7 +105,7 @@
"@types/node": "^22.9.0",
"@typescript-eslint/utils": "^8.15.0",
"dts-bundle-generator": "^9.5.1",
"eslint": "^9.14.0",
"eslint": "^9.17.0",
"eslint-define-config": "^2.1.0",
"lodash": "^4.17.21",
"publint": "^0.2.10",
Expand Down
3 changes: 2 additions & 1 deletion packages/eslint-config-sheriff/src/getAstroConfig.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import astro from 'eslint-plugin-astro';
import type { TSESLint } from '@typescript-eslint/utils';

export const getAstroConfig = (
hasReact: boolean,
customTSConfigPath: string | string[] | undefined,
) => {
): TSESLint.FlatConfig.ConfigArray => {
return [
...astro.configs.recommended,
...(hasReact ? astro.configs['jsx-a11y-strict'] : []),
Expand Down
36 changes: 18 additions & 18 deletions packages/eslint-config-sheriff/src/getBaseConfig.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
import eslintJs from '@eslint/js';
import type { TSESLint } from '@typescript-eslint/utils';
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 fsecond from 'eslint-plugin-fsecond';
import pluginImport from 'eslint-plugin-import';
import jsdoc from 'eslint-plugin-jsdoc';
import * as regexpPlugin from 'eslint-plugin-regexp';
import simpleImportSort from 'eslint-plugin-simple-import-sort';
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 stylistic from '@stylistic/eslint-plugin';
import * as regexpPlugin from 'eslint-plugin-regexp';
import { supportedFileTypes, allJsExtensions } from '@sherifforg/constants';
import tsdoc from 'eslint-plugin-tsdoc';
import unicorn from 'eslint-plugin-unicorn';
import globals from 'globals';
import tseslint from 'typescript-eslint';
import { fixupPluginRules } from '@eslint/compat';
import eslintJs 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 { getTsNamingConventionRule } from './utils/getTsNamingConventionRule';
import stylistic from '@stylistic/eslint-plugin';
import type { TSESLint } from '@typescript-eslint/utils';
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 globals from 'globals';
import { fixupPluginRules } from '@eslint/compat';
import { getTsNamingConventionRule } from './utils/getTsNamingConventionRule';

export const getBaseConfig = (
userConfigChoices: SheriffSettings,
Expand All @@ -39,7 +39,6 @@ export const getBaseConfig = (
},
{
files: [supportedFileTypes],
// @ts-expect-error
rules: getBaseEslintHandPickedRules(),
},
{
Expand All @@ -52,6 +51,7 @@ export const getBaseConfig = (
},
{
files: [supportedFileTypes],
// @ts-expect-error
rules: {
...typescriptHandPickedRules,
...getTsNamingConventionRule({ isTsx: false }),
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,27 +1,27 @@
/* eslint-disable @typescript-eslint/no-unnecessary-condition */
import getGitignorePatterns from 'eslint-config-flat-gitignore';
import lodash from 'lodash';
import type { FlatESLintConfig } from 'eslint-define-config';
import type { SheriffSettings } from '@sherifforg/types';
import lodash from 'lodash';
import { ignores, sheriffStartingOptions } from '@sherifforg/constants';
import { getReactConfig } from './getReactConfig';
import { getBaseConfig } from './getBaseConfig';
import { nextjsConfig } from './nextjsConfig';
import type { SheriffSettings } from '@sherifforg/types';
import type { TSESLint } from '@typescript-eslint/utils';
import { getAstroConfig } from './getAstroConfig';
import { getPlaywrightConfig } from './playwrightConfig';
import { lodashConfig } from './lodashConfig';
import { getBaseConfig } from './getBaseConfig';
import { getJestConfig } from './getJestConfig';
import { getReactConfig } from './getReactConfig';
import { getVitestConfig } from './getVitestConfig';
import { type TSESLint } from '@typescript-eslint/utils';
import { lodashConfig } from './lodashConfig';
import { nextjsConfig } from './nextjsConfig';
import { getPlaywrightConfig } from './playwrightConfig';
import { remedaConfig } from './remedaConfig';

export const getExportableConfig = (
userConfigChoices: SheriffSettings = sheriffStartingOptions,
/** @internal */
areAllRulesForced?: boolean,
): FlatESLintConfig[] => {
let exportableConfig: TSESLint.FlatConfig.ConfigArray = [
...getBaseConfig(userConfigChoices),
];
let exportableConfig: TSESLint.FlatConfig.ConfigArray =
getBaseConfig(userConfigChoices);

if (userConfigChoices.react || userConfigChoices.next) {
// we insert reactConfig this way because it's an array. It's an array because it contains multiple configs, currently: react, react-hooks, react-a11y and react-refresh.
Expand All @@ -48,7 +48,6 @@ export const getExportableConfig = (

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

if (userConfigChoices.playwright) {
exportableConfig.push(
//@ts-expect-error
...getPlaywrightConfig(userConfigChoices.pathsOverrides?.playwrightTests),
);
}
Expand All @@ -86,7 +84,7 @@ export const getExportableConfig = (
);

exportableConfig = exportableConfig.map((configSlice) => {
if (configSlice.ignores?.length && configSlice.ignores.length > 0) {
if (configSlice.ignores?.length && !lodash.isEmpty(configSlice.ignores)) {
return configSlice;
}

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

export const getJestConfig = (
pathsOverrides?: string[],
Expand All @@ -14,7 +14,6 @@ export const getJestConfig = (
`**/__tests__/**/*.{${allJsExtensions}}`,
],
extends: [jest.configs['flat/style']],
// @ts-expect-error
rules: {
...jestHandPickedRules,
'@typescript-eslint/unbound-method': 0, // see: https://github.com/jest-community/eslint-plugin-jest/blob/main/docs/rules/unbound-method.md
Expand Down
Loading
Loading