Skip to content

Commit

Permalink
Merge pull request #10 from SkwalExe/eslint
Browse files Browse the repository at this point in the history
improve eslint config
  • Loading branch information
SkwalExe authored May 23, 2024
2 parents 6fb19a2 + fb0caf3 commit c4b5cb6
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ git checkout -b my-new-feature
- When you finished your changes, you must check your code's formatting and linting and fix all the errors.

```bash
npm run lint-fix
npm run lint:fix
npm run format
```

Expand Down
26 changes: 13 additions & 13 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import eslint from '@eslint/js'
import tseslint from 'typescript-eslint'
import ts from 'typescript-eslint'
import eslintConfigPrettier from 'eslint-config-prettier'

export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommended,
export default ts.config(
...ts.configs.recommended,
eslintConfigPrettier,
// If ignores is used without any other keys in the configuration object, then the patterns act as global ignores.
// ref: https://eslint.org/docs/latest/use/configure/configuration-files#globally-ignoring-files-with-ignores
{
ignores: ['dist/**/*']
},
{
files: ['**/*.ts', 'eslint.config.mjs'],
rules: {
'indent': 'off', // conflicts with prettier
'eol-last': 'error',
'quotes': 'off', // conflicts
'prefer-arrow-callback': 'error',
'func-style': ['error', 'expression'],
'no-trailing-spaces': 'error',
Expand All @@ -22,11 +23,10 @@ export default tseslint.config(
'array-bracket-spacing': 'off',
'array-element-newline': ['error', 'consistent'],
'arrow-spacing': ['error', { before: true, after: true }],
'comma-dangle': 'off', // conflicts
'comma-spacing': ['error', { before: false, after: true }],
'linebreak-style': ['error', 'unix'],
'spaced-comment': ['error', 'always'],
'no-unused-vars': 'off',
},
},
'no-unused-vars': 'off'
}
}
)
20 changes: 20 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
"@babel/core": "^7.24.5",
"@babel/preset-env": "^7.24.5",
"@babel/preset-typescript": "^7.24.1",
"@eslint/js": "^9.2.0",
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-typescript": "^11.1.6",
"concurrently": "^8.2.2",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"prettier": "^3.2.5",
"rollup": "^4.17.2",
"rollup-plugin-livereload": "^2.0.5",
Expand All @@ -40,8 +40,8 @@
"typescript-eslint": "^7.8.0"
},
"scripts": {
"lint": "eslint **/*.ts",
"lint-fix": "eslint --fix **/*.ts",
"lint": "eslint .",
"lint:fix": "eslint --fix .",
"format": "prettier ./src/**/*.ts --config prettier.config.mjs --write",
"clean": "shx rm -rf ./dist",
"build:cjs": "tsc -m commonjs --target es2017 --outDir ./dist/lib-cjs/",
Expand Down
5 changes: 4 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ export const playSound = (path: string) => {
audio.play()
}

export const random = (list: unknown[]) => list[Math.floor(Math.random() * list.length)]
export const random = <T>(list: T[]): T => {
if (list.length === 0) throw new Error('random() got an empty array')
return list[Math.floor(Math.random() * list.length)]!
}

0 comments on commit c4b5cb6

Please sign in to comment.