Skip to content

Commit

Permalink
chore: set up eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio committed Jun 13, 2024
1 parent bb1c350 commit 77e01ce
Show file tree
Hide file tree
Showing 4 changed files with 1,337 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,8 @@ jobs:
- name: Build
run: pnpm build

- name: Lint
run: pnpm lint

- name: Test
run: pnpm test
78 changes: 78 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { readFileSync } from 'node:fs'
import eslint from '@eslint/js'
import tseslint from 'typescript-eslint'
import eslintPluginUnicorn from 'eslint-plugin-unicorn'
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended'

const tsconfig = JSON.parse(readFileSync('./tsconfig.json', 'utf8'))

export default defineConfig([
eslint.configs.recommended,
...tseslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked.map((config) => ({
...config,
files: tsconfig.include,
})),
{
files: tsconfig.include,
languageOptions: {
parserOptions: {
project: true,
tsconfigRootDir: import.meta.dirname,
},
},
},
{
languageOptions: {
globals: {
process: 'readonly',
},
},
},
{
plugins: { unicorn: eslintPluginUnicorn },
rules: { 'unicorn/prefer-node-protocol': 'error' },
},
{
// TODO: Must-have rules. Enable one-by-one
rules: {
'unicorn/prefer-node-protocol': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/require-await': 'off',
'@typescript-eslint/no-floating-promises': 'off',
'@typescript-eslint/no-misused-promises': 'off',
'no-constant-condition': 'off',
'no-empty': 'off',
'prefer-const': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/ban-types': 'off',
},
},
{
// TODO: Nice-to-have rules
rules: {
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/no-redundant-type-constituents': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unnecessary-type-assertion': 'off',
'@typescript-eslint/no-this-alias': 'off',
'@typescript-eslint/no-non-null-asserted-optional-chain': 'off',
'@typescript-eslint/no-namespace': 'off',
'@typescript-eslint/no-implied-eval': 'off',
},
},
{ ignores: ['dist'] },
eslintPluginPrettierRecommended,

// TODO: Must-have rules. Enable one-by-one
{ rules: { 'prettier/prettier': 'off' } },
])

/** @param config {import('eslint').Linter.FlatConfig} */
function defineConfig(config) {
return config
}
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,22 @@
"dev": "tsup --watch",
"build": "tsup",
"publish": "clean-publish",
"prepare": "husky install"
"prepare": "husky install",
"lint": "eslint"
},
"devDependencies": {
"@types/node": "^20.12.8",
"clean-publish": "^3.4.4",
"eslint": "^9.4.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-unicorn": "^53.0.0",
"husky": "^7.0.4",
"nano-staged": "^0.5.0",
"prettier": "^2.5.1",
"prettier": "^3.3.2",
"tsup": "^8.0.2",
"typescript": "^5.4.5",
"typescript-eslint": "^7.13.0",
"vite": "^5.2.11",
"vitest": "^1.6.0"
},
Expand Down
Loading

0 comments on commit 77e01ce

Please sign in to comment.