Skip to content

Commit

Permalink
Merge pull request #132 from AndreaPontrandolfo/feature/ts-eslint-v7
Browse files Browse the repository at this point in the history
updates to tseslint
  • Loading branch information
AndreaPontrandolfo authored Mar 24, 2024
2 parents 7718c88 + aa7501a commit 3a6e3c9
Show file tree
Hide file tree
Showing 12 changed files with 2,244 additions and 1,667 deletions.
7 changes: 7 additions & 0 deletions .changeset/strong-windows-hang.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'eslint-config-sheriff': minor
'sheriff-webservices': minor
---

chore(config): updated tseslint
chore(webservices): updated tseslint
4 changes: 3 additions & 1 deletion apps/docs-website/docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { version } from "eslint-config-sheriff/package.json";
const lightCodeTheme = themes.github;
const darkCodeTheme = themes.dracula;

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

const config: Config = {
title: "Sheriff",
tagline:
Expand Down Expand Up @@ -90,7 +92,7 @@ const config: Config = {
},
footer: {
style: "dark",
copyright: `Copyright © ${new Date().getFullYear()} Sheriff. Built with Docusaurus.`,
copyright: `Copyright © ${currentYear.toString()} Sheriff. Built with Docusaurus.`,
},
prism: {
theme: lightCodeTheme,
Expand Down
7 changes: 6 additions & 1 deletion apps/docs-website/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ export default defineFlatConfig([
},
},
{
ignores: [".docusaurus/**/*", ".turbo/**/*", "babel.config.js"],
ignores: [
".docusaurus/**/*",
".turbo/**/*",
"babel.config.js",
"CHANGELOG.md",
],
},
]);
5 changes: 2 additions & 3 deletions apps/sheriff-webservices/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
"@next/eslint-plugin-next": "^13.2.3",
"@regru/eslint-plugin-prefer-early-return": "^1.0.0",
"@stylistic/eslint-plugin": "^1.5.1",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"eslint": "^8.57.0",
"eslint-config-sheriff": "latest",
"eslint-plugin-arrow-return-style": "^1.2.2",
Expand All @@ -52,7 +50,8 @@
"eslint-plugin-unicorn": "^50.0.1",
"eslint-plugin-vitest": "^0.2.8",
"hono": "^3.12.0",
"lodash": "^4.17.21"
"lodash": "^4.17.21",
"typescript-eslint": "^7.3.1"
},
"packageManager": "[email protected]",
"engines": {
Expand Down
5 changes: 3 additions & 2 deletions apps/sheriff-webservices/src/getAllRules.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable import/newline-after-import */

import eslintRecommended from "@eslint/js";
import typescript from "@typescript-eslint/eslint-plugin";
import tseslint from "typescript-eslint";
import unicorn from "eslint-plugin-unicorn";
import sonarjs from "eslint-plugin-sonarjs";
import playwright from "eslint-plugin-playwright";
Expand Down Expand Up @@ -50,7 +50,8 @@ export const getAllRules = (
const rules: BarebonesConfigAtom["rules"] = {
...eslintRecommended.rules,
...prependRulesWithPluginName(
(typescript as unknown as Plugin).rules,
//@ts-expect-error
tseslint.plugin.rules ?? [],
"@typescript-eslint",
),
...prependRulesWithPluginName(unicorn.rules, "unicorn"),
Expand Down
9 changes: 5 additions & 4 deletions knip.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@
"packages/sheriff-utils",
"apps/config-validation-playground",
"apps/cli-playground",
"apps/docs-website"
"apps/docs-website",
],
"ignore": [
"packages/create-sheriff-config/src/utils/spinner.ts",
"packages/create-sheriff-config/src/utils/widgets.ts"
"packages/create-sheriff-config/src/utils/widgets.ts",
],
"ignoreDependencies": [
"@turbo/gen",
"commander",
"ora",
"eslint-import-resolver-typescript",
"type-fest"
"type-fest",
"@typescript-eslint/utils",
],
"ignoreBinaries": ["only-allow", "set"]
"ignoreBinaries": ["only-allow", "set"],
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"@manypkg/cli": "^0.21.1",
"@turbo/gen": "^1.9.7",
"create-sheriff-config": "workspace:*",
"knip": "^3.9.0",
"knip": "^5.2.2",
"prettier": "^3.1.1",
"turbo": "^1.11.2",
"typesync": "^0.12.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const askForEslintTsPatch = async (): Promise<boolean> => {
}

logger.error(
`Invalid response. Expected boolean, received ${eslintTsPatchConfirmValue}`,
`Invalid response. Expected boolean, received ${String(eslintTsPatchConfirmValue)}`,
);

return false;
Expand Down
6 changes: 3 additions & 3 deletions packages/eslint-config-sheriff/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@
"@next/eslint-plugin-next": "^13.2.3",
"@regru/eslint-plugin-prefer-early-return": "^1.0.0",
"@stylistic/eslint-plugin": "^1.5.1",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"astro-eslint-parser": "^0.16.3",
"eslint-config-flat-gitignore": "^0.1.3",
"eslint-config-prettier": "^9.0.0",
Expand All @@ -83,7 +81,8 @@
"eslint-plugin-storybook": "^0.6.11",
"eslint-plugin-tsdoc": "^0.2.17",
"eslint-plugin-unicorn": "^50.0.1",
"eslint-plugin-vitest": "^0.2.8"
"eslint-plugin-vitest": "^0.2.8",
"typescript-eslint": "^7.3.1"
},
"peerDependencies": {
"eslint": ">=8.23.0",
Expand All @@ -99,6 +98,7 @@
"@types/eslint-config-prettier": "^6.11.3",
"@types/lodash": "^4.14.191",
"@types/node": "^20.10.6",
"@typescript-eslint/utils": "^7.3.1",
"eslint": "^8.57.0",
"lodash": "^4.17.21",
"publint": "^0.2.7",
Expand Down
39 changes: 20 additions & 19 deletions packages/eslint-config-sheriff/src/getExportableConfig.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import eslintRecommended from '@eslint/js';
import typescriptParser from '@typescript-eslint/parser';
import typescript from '@typescript-eslint/eslint-plugin';
import tseslint from 'typescript-eslint';
import unicorn from 'eslint-plugin-unicorn';
import sonarjs from 'eslint-plugin-sonarjs';
import playwright from 'eslint-plugin-playwright';
Expand All @@ -20,7 +19,7 @@ import arrowReturnStyle from 'eslint-plugin-arrow-return-style';
import stylistic from '@stylistic/eslint-plugin';
import getGitignorePatterns from 'eslint-config-flat-gitignore';
import lodash from 'lodash';
import { ExportableConfigAtom, SheriffSettings } from '@sherifforg/types';
import { SheriffSettings } from '@sherifforg/types';
import { allJsExtensions, supportedFileTypes, ignores } from './constants';
import { fpHandPickedRules } from './fpHandPickedRules';
import { getBaseEslintHandPickedRules } from './getBaseEslintHandPickedRules';
Expand All @@ -42,7 +41,7 @@ const getLanguageOptionsTypescript = (
userChosenTSConfig?: string | string[],
) => {
return {
parser: typescriptParser,
parser: tseslint.parser,
parserOptions: {
ecmaFeatures: { modules: true },
project: userChosenTSConfig || true,
Expand All @@ -54,7 +53,7 @@ export const getLanguageOptionsTypescriptReact = (
userChosenTSConfig?: string | string[],
) => {
return {
parser: typescriptParser,
parser: tseslint.parser,
parserOptions: {
ecmaFeatures: { modules: true, jsx: true },
project: userChosenTSConfig || true,
Expand Down Expand Up @@ -143,24 +142,30 @@ const getBaseConfig = (userConfigChoices: SheriffSettings) => {
const { noRestrictedSyntaxOverride } = userConfigChoices;
const hasReact = Boolean(userConfigChoices.react);

return [
return tseslint.config(
{
files: [supportedFileTypes],
rules: eslintRecommended.configs.recommended.rules,
extends: [eslintRecommended.configs.recommended],
},
{
files: [supportedFileTypes],
//@ts-expect-error
rules: getBaseEslintHandPickedRules(noRestrictedSyntaxOverride),
},
{
files: [`**/*{${allJsExtensions}}`],
languageOptions: getLanguageOptionsTypescript(customTSConfigPath),
},
{
files: [supportedFileTypes],
extends: tseslint.configs.strictTypeChecked,
},
{
files: [supportedFileTypes],
plugins: {
'@typescript-eslint': typescript,
'@typescript-eslint': tseslint.plugin,
},
rules: {
...(typescript.configs['eslint-recommended'].overrides?.[0].rules ??
{}),
...typescript.configs['strict-type-checked'].rules,
...typescriptHandPickedRules,
...getTsNamingConventionRule({ isTsx: false }),
},
Expand All @@ -174,10 +179,6 @@ const getBaseConfig = (userConfigChoices: SheriffSettings) => {
'tsdoc/syntax': 2,
},
},
{
files: [supportedFileTypes],
rules: getBaseEslintHandPickedRules(noRestrictedSyntaxOverride),
},
{
files: [supportedFileTypes],
plugins: { '@stylistic': stylistic },
Expand Down Expand Up @@ -286,7 +287,7 @@ const getBaseConfig = (userConfigChoices: SheriffSettings) => {
reportUnusedDisableDirectives: 'error',
},
},
];
);
};

export const getExportableConfig = (
Expand All @@ -297,9 +298,7 @@ export const getExportableConfig = (
throw new Error('No settings provided.');
}

let exportableConfig: ExportableConfigAtom[] = [
...getBaseConfig(userConfigChoices),
];
let exportableConfig = [...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 Down Expand Up @@ -327,6 +326,7 @@ export const getExportableConfig = (

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

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

if (userConfigChoices.files) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export const typescriptHandPickedRules = {
'@typescript-eslint/ban-ts-comment': 0,
'@typescript-eslint/no-unsafe-assignment': 0,
'@typescript-eslint/no-array-constructor': 0,
'@typescript-eslint/use-unknown-in-catch-callback-variable': 0,
'@typescript-eslint/no-use-before-define': 2,
'@typescript-eslint/no-inferrable-types': 2,
'@typescript-eslint/no-loop-func': 2,
Expand Down
Loading

0 comments on commit 3a6e3c9

Please sign in to comment.