feat: add typescript eslint

This commit is contained in:
Guz013
2023-07-11 19:05:50 -03:00
parent c444ccbe1c
commit 487ab02c46
11 changed files with 322 additions and 158 deletions

View File

@@ -1,6 +1,6 @@
import readable from '@readable/core';
export default [
readable
]
import { defineConfig } from 'readable';
export default defineConfig({
strict: true,
tsconfig: '/home/work/Documents/Repositories/Readable/tsconfig.json'
})

View File

@@ -1,5 +1,5 @@
{
"name": "readable",
"name": "readable-monorepo",
"version": "1.0.0",
"description": "",
"main": "index.js",
@@ -13,7 +13,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"@readable/core": "workspace:*"
"readable": "workspace:*"
},
"devDependencies": {
"@changesets/cli": "^2.26.2",

View File

@@ -1,6 +1,3 @@
import type { Linter } from "eslint"
import { Config, ESConfig } from "./src/types";
export type ESConfig = Readonly<Linter.FlatConfig>;
const config: Config;
export default config;
export function defineConfig(config: Config): ESConfig[]

View File

@@ -1,6 +0,0 @@
/** @type {import('./index').ESConfig} */
const standard = {
}
export default standard

View File

@@ -1,20 +1,20 @@
{
"name": "@readable/core",
"name": "readable",
"version": "1.0.0",
"description": "",
"main": "index.js",
"module": "./index.js",
"source": "./index.js",
"exports": {
"default": "./index.js",
"import": "./index.js",
"types": "./index.d.ts"
},
"type": "module",
"types": "./index.js",
"module": "./src/index.js",
"source": "./src/index.js",
"exports": {
"default": "./src/index.js",
"import": "./src/index.js",
"types": "./index.d.ts"
},
"type": "module",
"types": "./src/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"lint": "ESLINT_USE_FLAT_CONFIG=true eslint ."
"lint": "ESLINT_USE_FLAT_CONFIG=true eslint ."
},
"keywords": [],
"author": "",
@@ -22,6 +22,13 @@
"devDependencies": {
"@eslint/js": "^8.44.0",
"@types/eslint__js": "^8.42.0",
"@types/node": "^20.4.1",
"eslint": "^8.44.0"
},
"dependencies": {
"@eslint/eslintrc": "^2.1.0",
"@typescript-eslint/eslint-plugin": "^5.45.0",
"@typescript-eslint/parser": "^5.45.0",
"typescript": "^5.0.0"
}
}

View File

@@ -0,0 +1,16 @@
// @ts-ignore
import { FlatCompat } from "@eslint/eslintrc";
import javascript from "@eslint/js";
import path from "node:path";
import { fileURLToPath } from "node:url";
// mimic CommonJS variables
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
export const eslintrc = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: javascript.configs.recommended,
allConfig: javascript.configs.all,
});

View File

@@ -0,0 +1,55 @@
import { eslintrc } from './eslintrc-compact.js';
import rules from './rules.js';
import tsEslint from '@typescript-eslint/eslint-plugin';
import tsParser from '@typescript-eslint/parser';
import js from '@eslint/js';
/**
* @param {import('./types').Config} config
*
* @returns {import('./types').ESConfig[]}
*/
export function defineConfig({
tsconfig,
// indent = 'tab',
strict = true,
}) {
return [
{
ignores: [
'**/node_modules',
'**/dist',
'**/fixtures',
]
},
js.configs.recommended,
{
plugins: {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
'@typescript-eslint': tsEslint
},
languageOptions: {
sourceType: 'module',
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
parser: tsParser,
parserOptions: {
project: tsconfig,
// eslint-disable-next-line no-undef
tsconfigRootDir: process.cwd()
}
},
files: ['**/*.ts', '**/*.js'],
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
rules: {
...tsEslint.configs.recommended.rules,
...tsEslint.configs['recommended-requiring-type-checking'].rules,
...tsEslint.configs['eslint-recommended'].rules,
...(strict ? tsEslint.configs.strict.rules : null)
}
}
]
}

View File

@@ -0,0 +1,73 @@
export default {
/**
* @see {@link https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/configs/strict-type-checked.ts}
*/
tsChecked: {
'@typescript-eslint/await-thenable': 'error',
'@typescript-eslint/ban-ts-comment': 'error',
'@typescript-eslint/ban-types': 'error',
'no-array-constructor': 'off',
'@typescript-eslint/no-array-constructor': 'error',
'@typescript-eslint/no-base-to-string': 'error',
'@typescript-eslint/no-duplicate-enum-values': 'error',
// // '@typescript-eslint/no-duplicate-type-constituents': 'error',
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/no-extra-non-null-assertion': 'error',
'@typescript-eslint/no-floating-promises': 'error',
'@typescript-eslint/no-for-in-array': 'error',
'no-implied-eval': 'off',
'@typescript-eslint/no-implied-eval': 'error',
'no-loss-of-precision': 'off',
'@typescript-eslint/no-loss-of-precision': 'error',
'@typescript-eslint/no-misused-new': 'error',
'@typescript-eslint/no-misused-promises': 'error',
'@typescript-eslint/no-namespace': 'error',
'@typescript-eslint/no-non-null-asserted-optional-chain': 'error',
'@typescript-eslint/no-redundant-type-constituents': 'error',
'@typescript-eslint/no-this-alias': 'error',
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
'@typescript-eslint/no-unnecessary-type-constraint': 'error',
'@typescript-eslint/no-unsafe-argument': 'error',
'@typescript-eslint/no-unsafe-assignment': 'error',
'@typescript-eslint/no-unsafe-call': 'error',
'@typescript-eslint/no-unsafe-declaration-merging': 'error',
// '@typescript-eslint/no-unsafe-enum-comparison': 'error',
'@typescript-eslint/no-unsafe-member-access': 'error',
'@typescript-eslint/no-unsafe-return': 'error',
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': 'error',
'@typescript-eslint/no-var-requires': 'error',
'@typescript-eslint/prefer-as-const': 'error',
'require-await': 'off',
'@typescript-eslint/require-await': 'error',
'@typescript-eslint/restrict-plus-operands': 'error',
'@typescript-eslint/restrict-template-expressions': 'error',
'@typescript-eslint/triple-slash-reference': 'error',
'@typescript-eslint/unbound-method': 'error',
},
tsCheckedStrict: {
'@typescript-eslint/adjacent-overload-signatures': 'error',
'@typescript-eslint/array-type': 'error',
'@typescript-eslint/ban-tslint-comment': 'error',
'@typescript-eslint/class-literal-property-style': 'error',
'@typescript-eslint/consistent-generic-constructors': 'error',
'@typescript-eslint/consistent-indexed-object-style': 'error',
'@typescript-eslint/consistent-type-assertions': 'error',
'@typescript-eslint/consistent-type-definitions': 'error',
'dot-notation': 'off',
'@typescript-eslint/dot-notation': 'error',
'@typescript-eslint/no-confusing-non-null-assertion': 'error',
'no-empty-function': 'off',
'@typescript-eslint/no-empty-function': 'error',
'@typescript-eslint/no-empty-interface': 'error',
'@typescript-eslint/no-inferrable-types': 'error',
'@typescript-eslint/non-nullable-type-assertion-style': 'error',
'@typescript-eslint/prefer-for-of': 'error',
'@typescript-eslint/prefer-function-type': 'error',
'@typescript-eslint/prefer-namespace-keyword': 'error',
'@typescript-eslint/prefer-nullish-coalescing': 'error',
'@typescript-eslint/prefer-optional-chain': 'error',
'@typescript-eslint/prefer-string-starts-ends-with': 'error',
}
}

9
packages/core/src/types.d.ts vendored Normal file
View File

@@ -0,0 +1,9 @@
import type { Linter } from "eslint"
export type ESConfig = Readonly<Linter.FlatConfig>;
export interface Config {
tsconfig?: string | string[];
indent?: 'tab' | 'space';
strict?: boolean;
}

266
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@@ -10,8 +10,9 @@
"strict": true,
"module": "ES2022",
"target": "ES2022",
"alwaysStrict": true
"alwaysStrict": true,
"outDir": "./dir"
},
"include": ["**/*"],
"include": ["**/*.ts", "**/*.js"],
"exclude": ["./node_modules/**", "./dist/**"]
}