Skip to content

Commit

Permalink
ci(lint): add eslint and prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
moontai0724 committed Jun 24, 2023
1 parent 96a3484 commit 4d790f6
Show file tree
Hide file tree
Showing 10 changed files with 1,708 additions and 14 deletions.
108 changes: 108 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
{
"parser": "vue-eslint-parser",
"parserOptions": {
"parser": "@typescript-eslint/parser",
"project": "./tsconfig.json",
"extraFileExtensions": [".vue"],
"sourceType": "module"
},
"plugins": [
"@typescript-eslint/eslint-plugin",
"simple-import-sort",
"import"
],
"extends": [
"eslint:all",
"@nuxtjs/eslint-config-typescript",
"plugin:vue/vue3-recommended",
"plugin:@typescript-eslint/all",
"plugin:typescript-sort-keys/recommended",
"prettier"
],
"root": true,
"env": {
"node": true
},
"rules": {
// disabled rules (required)
"no-void": "off", // To call promise functions without other actions
"no-magic-numbers": "off", // This will wrongly detect a number passed to a function as a magic number
"@typescript-eslint/no-magic-numbers": "off",
"new-cap": "off", // The decorators will be wrongly detected
"class-methods-use-this": "off", // some methods are not using this
"require-await": "off", // it will wrongly detect async methods as not having await
"@typescript-eslint/require-await": "off",
"max-params": "off", // injection constructors need many parameters

// disabled rules (optional, in personal preference)
"no-console": "off", // This will disable console.log, console.error, etc. This could be removed if we have our own logger
"one-var": "off", // in favor to not merge variables to one
"no-continue": "off", // in favor to use continue

// disabled typescript-eslint rules (too strict)
"@typescript-eslint/promise-function-async": "off",
"@typescript-eslint/explicit-member-accessibility": "off",
"@typescript-eslint/prefer-readonly-parameter-types": "off",
"@typescript-eslint/parameter-properties": "off",
"@typescript-eslint/no-extraneous-class": "off",
"@typescript-eslint/no-misused-promises": "off",
"@typescript-eslint/member-ordering": "off",
"@typescript-eslint/no-type-alias": "off",
"@typescript-eslint/unbound-method": "off",
"@typescript-eslint/strict-boolean-expressions": "off",

// modified rules
"func-style": ["error", "declaration", { "allowArrowFunctions": true }],

// replaced rules
"no-useless-constructor": "off",
"@typescript-eslint/no-useless-constructor": "error",

"no-shadow": "off",
"@typescript-eslint/no-shadow": "error",

"sort-imports": "off",
"simple-import-sort/imports": "error",
"simple-import-sort/exports": "error",
"import/first": "error",
"import/newline-after-import": "error",
"import/no-duplicates": "error",

// additional rules
"@typescript-eslint/consistent-type-exports": "error",
"@typescript-eslint/consistent-type-imports": [
"error",
{
"fixStyle": "inline-type-imports"
}
],

"padding-line-between-statements": [
"error",
{ "blankLine": "always", "prev": "*", "next": "return" },
{
"blankLine": "always",
"prev": ["const", "let", "var", "multiline-expression"],
"next": "*"
},
{
"blankLine": "any",
"prev": ["const", "let", "var"],
"next": ["const", "let", "var"]
}
],
"@typescript-eslint/interface-name-prefix": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-unused-vars": "error"
},
"overrides": [
{
"files": ["*.spec.ts", "*.e2e-spec.ts"],
"rules": {
"@typescript-eslint/init-declarations": "off",
"max-lines-per-function": "off"
}
}
]
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ node_modules
logs
*.log

# Linter
.eslintcache

# Misc
.DS_Store
.fleet
Expand Down
7 changes: 7 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
build
dist
coverage
e2e
node_modules
pnpm-lock.yaml
*.lock
8 changes: 8 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"arrowParens": "avoid",
"endOfLine": "auto",
"semi": true,
"singleQuote": false,
"tabWidth": 2,
"trailingComma": "all"
}
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["vue.volar", "vue.vscode-typescript-vue-plugin"]
}
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.codeActionsOnSave": {
"source.fixAll": false,
"source.fixAll.eslint": true
}
}
7 changes: 5 additions & 2 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
devtools: { enabled: true }
})
devtools: { enabled: true },
typescript: {
strict: true,
},
});
15 changes: 14 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "nuxt-app",
"private": true,
"scripts": {
"lint": "eslint --ext .ts,.js,.vue --ignore-path .gitignore .",
"build": "nuxt build",
"dev": "nuxt dev",
"generate": "nuxt generate",
Expand All @@ -10,8 +11,20 @@
},
"devDependencies": {
"@nuxt/devtools": "latest",
"@nuxtjs/eslint-config-typescript": "^12.0.0",
"@types/node": "^18",
"@typescript-eslint/eslint-plugin": "^5.60.0",
"@typescript-eslint/parser": "^5.60.0",
"eslint": "^8.43.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-simple-import-sort": "^10.0.0",
"eslint-plugin-typescript-sort-keys": "^2.3.0",
"eslint-plugin-vue": "^9.15.0",
"nuxt": "^3.6.0",
"typescript": "^5.0.0"
"prettier": "^2.8.8",
"typescript": "^5.0.0",
"vue-tsc": "^1.8.1"
}
}
Loading

0 comments on commit 4d790f6

Please sign in to comment.