Skip to content

Commit

Permalink
refactor: setup eslint and autofix
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonkuhrt committed Mar 6, 2022
1 parent 168fb8f commit 0217dd2
Show file tree
Hide file tree
Showing 51 changed files with 1,559 additions and 690 deletions.
6 changes: 6 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.yalc
.vscode
.github
node_modules
dist-cjs
dist-esm
57 changes: 57 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": ["tsconfig.json"]
},
"plugins": [
// This enables using new lint rules powered by the TypeScript compiler API.
// https://github.com/typescript-eslint/typescript-eslint
"@typescript-eslint",
// This makes it so the IDE reports lint rejections as warnings only. This is
// better than errors because most lint rejections are not runtime errors. This
// allows IDE errors to be exclusive for e.g. static type errors which often are
// reflective of real runtime errors.
// https://github.com/bfanger/eslint-plugin-only-warn
"only-warn",
// This enables the use of a lint rule to reject function declarations. This is
// preferable as a way to encourage higher order function usage. For example it is not
// possible to wrap a function declaration with Open Telemetry instrumentation but it is
// possible to wrap an arrow function since its an expression.
// https://github.com/TristonJ/eslint-plugin-prefer-arrow
"prefer-arrow",
// This enables the use of a lint rule to reject use of @deprecated functions.
// https://github.com/gund/eslint-plugin-deprecation
"deprecation",
// Import sorting integrated into ESLint.
// https://github.com/lydell/eslint-plugin-simple-import-sort
"simple-import-sort",
// https://github.com/microsoft/tsdoc/tree/master/eslint-plugin
"tsdoc"
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"prettier"
],
"overrides": [],
"rules": {
"quotes": ["warn", "backtick"],
"tsdoc/syntax": "warn",
"simple-import-sort/imports": [
"warn",
{
"groups": []
}
],
"simple-import-sort/exports": "warn",
"deprecation/deprecation": "warn",
"prefer-arrow/prefer-arrow-functions": "warn",
// TypeScript makes these safe & effective
"no-case-declarations": "off",
// Same approach used by TypeScript noUnusedLocals
"@typescript-eslint/no-unused-vars": ["warn", { "varsIgnorePattern": "^_", "argsIgnorePattern": "^_" }]
}
}
2 changes: 1 addition & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const config = {
`jest-watch-select-projects`,
`jest-watch-suspend`,
],
setupFiles: ['./tests/_setup.ts'],
setupFiles: [`./tests/_setup.ts`],
}

export default config
6 changes: 3 additions & 3 deletions jest.config.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import baseConfig from './jest.config'

const config = {
...baseConfig,
testRegex: 'src/.*\\.spec\\.ts$',
testRegex: `src/.*\\.spec\\.ts$`,
displayName: {
name: 'Unit',
color: 'blue',
name: `Unit`,
color: `blue`,
},
}

Expand Down
12 changes: 12 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
"build": "yarn clean && yarn build:cjs && yarn build:esm",
"build:cjs": "tsc --project tsconfig.cjs.json",
"build:esm": "tsc --project tsconfig.esm.json",
"lint": "eslint . --ext .ts,.tsx --fix",
"lint:check": "eslint . --ext .ts,.tsx --max-warnings 0",
"clean": "rm -rf dist-cjs dist-esm node_modules/.cache",
"dev": "tsc --watch",
"type-check": "yarn tsc --noEmit",
Expand Down Expand Up @@ -59,10 +61,20 @@
"@swc/jest": "^0.2.20",
"@tsconfig/node14": "^1.0.1",
"@types/common-tags": "1.8.1",
"@types/eslint": "^8",
"@types/jest": "27.4.1",
"@types/node": "17.0.21",
"@types/tmp": "0.2.3",
"@typescript-eslint/eslint-plugin": "^5.13.0",
"@typescript-eslint/parser": "^5.13.0",
"doctoc": "1.4.0",
"eslint": "^8.10.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-deprecation": "^1.3.2",
"eslint-plugin-only-warn": "^1.0.3",
"eslint-plugin-prefer-arrow": "^1.2.3",
"eslint-plugin-simple-import-sort": "^7.0.0",
"eslint-plugin-tsdoc": "^0.2.14",
"jest": "27.5.1",
"jest-watch-select-projects": "^2.0.0",
"jest-watch-suspend": "1.1.2",
Expand Down
Loading

0 comments on commit 0217dd2

Please sign in to comment.