Skip to content

Commit

Permalink
feat: Add eslint and prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
Xy2002 committed Aug 1, 2024
1 parent 316c623 commit 3afa173
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 42 deletions.
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pnpm-lock.yaml
LICENSE
LICENSE.md
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"singleQuote": true,
"semi": true,
"printWidth": 100,
"trailingComma": "none",
"tabWidth": 4
}
33 changes: 7 additions & 26 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,9 @@
{
// Disable the default formatter, use eslint instead
"prettier.enable": false,
"editor.formatOnSave": false,

// Auto fix
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit",
"source.organizeImports": "never"
},

// Silent the stylistic rules in you IDE, but still auto fix them
"eslint.rules.customizations": [
{ "rule": "style/*", "severity": "off", "fixable": true },
{ "rule": "format/*", "severity": "off", "fixable": true },
{ "rule": "*-indent", "severity": "off", "fixable": true },
{ "rule": "*-spacing", "severity": "off", "fixable": true },
{ "rule": "*-spaces", "severity": "off", "fixable": true },
{ "rule": "*-order", "severity": "off", "fixable": true },
{ "rule": "*-dangle", "severity": "off", "fixable": true },
{ "rule": "*-newline", "severity": "off", "fixable": true },
{ "rule": "*quotes", "severity": "off", "fixable": true },
{ "rule": "*semi", "severity": "off", "fixable": true }
],

// Enable eslint for all supported languages
"eslint.validate": ["javascript", "javascriptreact", "typescript", "typescriptreact", "vue", "html", "markdown", "json", "jsonc", "yaml", "toml", "xml", "gql", "graphql", "astro", "svelte", "css", "less", "scss", "pcss", "postcss"]
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"files.autoSave": "onFocusChange",
"prettier.requireConfig": true,
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}
40 changes: 29 additions & 11 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
import antfu from '@antfu/eslint-config'
import globals from 'globals';
import pluginJs from '@eslint/js';
import { FlatCompat } from '@eslint/eslintrc';
import path from 'path';
import { fileURLToPath } from 'url';

export default antfu({
type: 'lib',
stylistic: {
indent: 4,
},
}, {
rules: {
'no-console': ['off'],
'semi': ['error', 'always'],
// mimic CommonJS variables -- not needed if using CommonJS
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const compat = new FlatCompat({
baseDirectory: __dirname,
resolvePluginsRelativeTo: __dirname,
recommendedConfig: pluginJs.configs.recommended
});

const jsRules = {
'no-prototype-builtins': 'off'
};

/** @type {import('eslint').Linter.Config[]} */
export default [
{
files: ['**/*.{mjs,cjs,js}'],
languageOptions: { globals: { ...globals.browser, ...globals.node } },
rules: {
...jsRules
}
},
})
...compat.extends('plugin:prettier/recommended')
];
15 changes: 10 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,30 +38,35 @@
"test": "vitest",
"test-ui": "vitest --ui",
"lint": "eslint .",
"lint:fix": "eslint . --fix"
"lint:fix": "eslint . --fix",
"format": "prettier --write ."
},
"dependencies": {
"date-fns": "^3.6.0"
},
"devDependencies": {
"@antfu/eslint-config": "^2.24.1",
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.8.0",
"@vitest/ui": "^2.0.5",
"colorette": "^2.0.20",
"del-cli": "^5.1.0",
"docdash-extended-chensuiyi": "^1.1.1",
"eslint": "9.x",
"eslint": "^9.8.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"fs-extra": "^11.2.0",
"globals": "^15.9.0",
"jsdoc": "^4.0.3",
"lint-staged": "^15.2.7",
"log-symbols": "^6.0.0",
"prettier": "^3.3.3",
"simple-git-hooks": "^2.11.1",
"vitest": "^2.0.5"
},
"simple-git-hooks": {
"pre-commit": "pnpm lint-staged"
},
"lint-staged": {
"*": "eslint --fix"
"*": "prettier --write ."
}
}
}

0 comments on commit 3afa173

Please sign in to comment.