config: add some tools config

This commit is contained in:
Sagi 2022-09-13 17:21:32 +08:00
parent f47aaffd46
commit 6b27372b15
29 changed files with 9561 additions and 52 deletions

5
.eslintignore Normal file
View File

@ -0,0 +1,5 @@
node_modules/*
packages/**/node_modules/*
packages/**/dist/*
packages/**/build/*
packages/**/lib/*

7
.eslintrc Normal file
View File

@ -0,0 +1,7 @@
{
"root": true,
"extends": ["@farris"],
"rules": {
"prefer-object-spread": "off"
}
}

4
.husky/commit-msg Executable file
View File

@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
npx --no-install commitlint --edit ${1}

4
.husky/pre-commit Executable file
View File

@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
npx @ls-lint/ls-lint && npx lint-staged --allow-empty

30
.ls-lint.yml Normal file
View File

@ -0,0 +1,30 @@
ls:
packages/**:
.dir: kebab-case | regex:__[a-z0-9]+__
.scss: kebab-case
.vue: kebab-case
.js: kebab-case | pointcase
.ts: kebab-case | pointcase
.tsx: kebab-case | pointcase
.component.tsx: kebab-case
.props.ts: kebab-case
.spec.ts: kebab-case
.spec.tsx: kebab-case
.route.ts: kebab-case
.type.ts: kebab-case
.d.ts: kebab-case
ignore:
# docs-vue
- packages/docs-vue/.vscode
- packages/docs-vue/public
- packages/docs-vue/node_modules
- packages/docs-vue/dist
# ui-vue
- packages/ui-vue/.vscode
- packages/ui-vue/node_modules
- packages/ui-vue/dist
- packages/ui-vue/public
# eslint-config
- packages/eslint-config/node_modules
- packages/eslint-config/test

1
.npmrc Normal file
View File

@ -0,0 +1 @@
enable-pre-post-scripts=true

13
.prettierrc Normal file
View File

@ -0,0 +1,13 @@
{
"bracketSpacing": true,
"jsxBracketSameLine": true,
"jsxSingleQuote": false,
"printWidth": 140,
"semi": true,
"useTabs": false,
"trailingComma": "es5",
"singleQuote": true,
"tabWidth": 2,
"endOfLine": "auto",
"proseWrap": "preserve"
}

50
.stylelintrc.json Normal file
View File

@ -0,0 +1,50 @@
{
"extends": [
"stylelint-config-standard",
"stylelint-config-recommended-scss"
],
"plugins": [
"stylelint-scss"
],
"rules": {
"string-quotes": "single",
"property-no-unknown": true,
"selector-pseudo-class-no-unknown": true,
"at-rule-empty-line-before": ["always",{
"except":["blockless-after-same-name-blockless","first-nested","inside-block"],
"ignore": ["after-comment", "first-nested"]
}],
"rule-empty-line-before":["always",{
"except": [ "after-single-line-comment", "first-nested"]
}],
"block-no-empty": true,
"selector-pseudo-element-no-unknown": [
true,
{
"ignorePseudoElements": [
"ng-deep"
]
}
],
"selector-type-no-unknown": [
true,
{
"ignoreTypes": [
"/^d-/"
]
}
],
"color-hex-length": "long",
"no-descending-specificity": null,
"font-family-no-missing-generic-family-keyword": null,
"no-duplicate-selectors": null,
"declaration-block-no-duplicate-properties": [
true,
{
"ignore": [
"consecutive-duplicates"
]
}
]
}
}

118
commitlint.config.js Normal file
View File

@ -0,0 +1,118 @@
const types = ['config','feature', 'fix', 'docs', 'style', 'refactor', 'performance', 'test', 'build', 'release', 'chore', 'revert'];
module.exports = {
parserPreset: {parserOpts: {headerPattern: /^(\w*)(?:\((.*)\))?!?: (.*)$/}},
extends: ['@commitlint/config-conventional'],
rules: {
'type-empty': [2, 'never'],
'type-enum': [2, 'always', types],
'scope-case': [0, 'always'],
'subject-empty': [2, 'never'],
'subject-case': [0, 'never'],
'header-max-length': [2, 'always', 88],
},
prompt: {
questions: {
type: {
description: "Select the type of change that you're committing",
enum: {
config:{
description: 'Changes that affect the tools, such as eslint, npm, vscode.',
title: 'Config',
emoji: '🛠',
},
feature: {
description: 'A new feature',
title: 'Features',
emoji: '✨',
},
fix: {
description: 'A bug fix',
title: 'Bug Fixes',
emoji: '🐛',
},
docs: {
description: 'Documentation only changes',
title: 'Documentation',
emoji: '📚',
},
style: {
description:
'Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)',
title: 'Styles',
emoji: '💎',
},
refactor: {
description:
'A code change that neither fixes a bug nor adds a feature',
title: 'Code Refactoring',
emoji: '📦',
},
performance: {
description: 'A code change that improves performance',
title: 'Performance Improvements',
emoji: '🚀',
},
test: {
description: 'Adding missing tests or correcting existing tests',
title: 'Tests',
emoji: '🚨',
},
build: {
description:
'Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)',
title: 'Builds',
emoji: '🛠',
},
ci: {
description:
'Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)',
title: 'Continuous Integrations',
emoji: '⚙️',
},
chore: {
description: "Other changes that don't modify src or test files",
title: 'Chores',
emoji: '♻️',
},
revert: {
description: 'Reverts a previous commit',
title: 'Reverts',
emoji: '🗑',
}
}
},
scope: {
description:
'What is the scope of this change (e.g. component or file name)',
},
subject: {
description:
'Write a short, imperative tense description of the change',
},
body: {
description: 'Provide a longer description of the change',
},
isBreaking: {
description: 'Are there any breaking changes?',
},
breakingBody: {
description:
'A BREAKING CHANGE commit requires a body. Please enter a longer description of the commit itself',
},
breaking: {
description: 'Describe the breaking changes',
},
isIssueAffected: {
description: 'Does this change affect any open issues?',
},
issuesBody: {
description:
'If issues are closed, the commit requires a body. Please enter a longer description of the commit itself',
},
issues: {
description: 'Add issue references (e.g. "fix #123", "re #123".)',
},
},
}
};

View File

@ -1,8 +1,34 @@
{ {
"name": "farris-vue", "name": "farris-vue",
"private": true, "private": true,
"scripts": {
"prepare": "husky install"
},
"devDependencies": { "devDependencies": {
"lerna": "^4.0.0" "@commitlint/cli": "^17.1.0",
"@commitlint/config-conventional": "^17.1.0",
"@farris/eslint-config": "^1.0.0",
"@ls-lint/ls-lint": "^1.11.0",
"@types/jest": "^29.0.1",
"@types/lodash": "^4.14.182",
"@types/node": "^18.7.16",
"esbuild-register": "^3.3.0",
"eslint": "^8.23.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-vue": "^9.4.0",
"husky": "^8.0.0",
"intersection-observer": "^0.12.2",
"lerna": "^4.0.0",
"lint-staged": "^13.0.0",
"npm-run-all": "^4.1.5",
"stylelint": "^14.11.0",
"stylelint-config-recommended-scss": "^7.0.0",
"stylelint-config-standard": "^28.0.0",
"stylelint-scss": "^3.3.1"
},
"lint-staged": {
"packages/**/{*.vue,*.js,*.ts,*.jsx,*.tsx}": "eslint --fix",
"packages/**/{*.scss,*.css}": "stylelint --fix"
}, },
"workspaces": [ "workspaces": [
"packages/*" "packages/*"

View File

@ -1,7 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref } from 'vue' import { ref } from 'vue'
defineProps<{ msg: string }>() defineProps<{ msg: string }>();
const count = ref(0) const count = ref(0)
</script> </script>

View File

@ -0,0 +1,174 @@
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
extends: [
'plugin:vue/vue3-recommended',
'airbnb-base',
'plugin:@typescript-eslint/recommended',
'prettier',
],
parserOptions: {
parser: '@typescript-eslint/parser',
ecmaVersion: 2019,
sourceType: 'module',
ecmaFeatures: {
jsx: true,
tsx: true,
},
extraFileExtensions: ['.vue'],
},
plugins: ['@typescript-eslint'],
env: {
es6: true,
node: true,
jest: true,
browser: true,
},
rules: {
'accessor-pairs': 'off',
'array-callback-return': 'off',
'curly': 'error',
'class-methods-use-this': 'off',
'complexity': [
'error',
{
max: 40,
},
],
'consistent-return': 'off',
'default-case': 'off',
'eol-last': 'error',
'eqeqeq': ['error', 'smart'],
'func-names': 'off',
// eslint-plugin-import
'import/order': 'off',
'import/extensions': 'off',
'import/no-unresolved': 'off',
'import/prefer-default-export': 'off',
'import/no-extraneous-dependencies': 'off',
'max-depth': 'off',
'max-len': ['error', { code: 140 }],
'max-nested-callbacks': ['error', 6],
'max-params': 'off',
'no-new': 'off',
'no-bitwise': 'off',
// 'no-console': 'off',
'no-console': [
'error',
{
allow: [
'log',
'warn',
'dir',
'timeLog',
'assert',
'clear',
'count',
'countReset',
'group',
'groupEnd',
'table',
'dirxml',
'error',
'groupCollapsed',
'Console',
'profile',
'profileEnd',
'timeStamp',
'context',
]
}
],
'no-multiple-empty-lines': 'error',
'no-restricted-globals': 'off',
'no-shadow': 'off',
'no-trailing-spaces': 'error',
'no-param-reassign': 'off',
'no-plusplus': 'off',
'no-nested-ternary': 'off',
'no-underscore-dangle': 'off',
'no-unused-expressions': 'off',
'no-unused-labels': 'error',
'no-use-before-define': 'error',
'no-useless-constructor': 'off',
'no-useless-concat': 'off',
'no-var': 'error',
'prefer-const': 'error',
'prefer-destructuring': ['error', { object: true, array: false }],
'prefer-promise-reject-errors': 'off',
'prefer-template': 'off',
'semi': 'error',
'space-in-parens': ['error', 'never'],
'spaced-comment': ['error', 'always'],
// typescript-eslint
'@typescript-eslint/camelcase': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-unused-vars': 'error',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-useless-constructor': 'off',
'@typescript-eslint/no-parameter-properties': 'off',
'@typescript-eslint/no-require-imports': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/dot-notation': 'off',
'@typescript-eslint/indent': [
'error',
2,
{ FunctionDeclaration: { parameters: 'first' }, FunctionExpression: { parameters: 'first' } },
],
'@typescript-eslint/member-delimiter-style': [
'error',
{
multiline: {
delimiter: 'semi',
requireLast: true,
},
singleline: {
delimiter: 'semi',
requireLast: false,
},
},
],
'@typescript-eslint/no-misused-new': 'error',
'@typescript-eslint/no-non-null-assertion': 'error',
'@typescript-eslint/prefer-function-type': 'error',
'@typescript-eslint/semi': ['error', 'always'],
'@typescript-eslint/type-annotation-spacing': 'error',
'@typescript-eslint/unified-signatures': 'error',
'@typescript-eslint/no-shadow': 'error',
'@typescript-eslint/member-ordering': 'off',
'@typescript-eslint/no-this-alias': 'off',
// eslint-plugin-vue
'vue/no-v-html': 'off',
'vue/attributes-order': 'off',
'vue/require-v-for-key': 'off',
'vue/require-default-prop': 'off',
'vue/no-unused-components': 'off',
'vue/multi-word-component-names': 'off',
'vue/return-in-computed-property': 'off'
},
overrides: [
{
files: ['*.vue'],
parser: require.resolve('vue-eslint-parser'),
},
{
files: ['**/*.md/*.js', '**/*.md/*.ts'],
rules: {
'@typescript-eslint/no-unused-vars': 'off',
},
},
],
};

View File

@ -0,0 +1,4 @@
/** @type {import('@jest/types').Config.InitialOptions} */
module.exports = {
resolver: '<rootDir>/jest.resolver.js',
};

View File

@ -0,0 +1,13 @@
// https://github.com/facebook/jest/issues/9771#issuecomment-871585234
const resolver = require('enhanced-resolve').create.sync({
conditionNames: ['require', 'node', 'default'],
extensions: ['.js', '.json', '.node', '.ts', '.tsx'],
});
module.exports = function (request, options) {
// list global module that must be resolved by defaultResolver here
if (['fs', 'http', 'path'].includes(request)) {
return options.defaultResolver(request, options);
}
return resolver(options.basedir, request);
};

View File

@ -0,0 +1,26 @@
{
"name": "@farris/eslint-config",
"version": "1.0.0",
"dependencies": {
"@typescript-eslint/eslint-plugin": "^5.36.1",
"@typescript-eslint/parser": "^5.36.1",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-vue": "^9.4.0",
"enhanced-resolve": "^5.10.0",
"vue": "^3.2.37"
},
"devDependencies": {
"eslint": "^8.23.0",
"typescript": "^4.8.2",
"@vitejs/plugin-vue": "^3.1.0",
"@vitejs/plugin-vue-jsx": "^2.0.1",
"@vue/babel-plugin-jsx": "^1.1.1",
"vite": "^3.1.0",
"vue-tsc": "^0.40.4"
},
"peerDependencies": {
"eslint": "^7.32.0 || ^8.2.0"
}
}

View File

@ -0,0 +1,4 @@
{
"root": true,
"extends": ["../index"]
}

View File

@ -0,0 +1,41 @@
const { ESLint } = require('eslint');
const path = require('path');
const eslint = new ESLint();
async function lintProject(name) {
const projectPath = path.resolve(__dirname, name);
const filesToLint = path.resolve(projectPath, '**');
const rest = await eslint.lintFiles(filesToLint);
const ruleId = [];
rest.forEach((res) =>
res.messages.forEach((msg) => {
if (ruleId.indexOf(msg.ruleId) < 0) {
ruleId.push(msg.ruleId);
}
})
);
return ruleId;
}
test('a vue project should pass lint', async () => {
const rest = await lintProject('vue');
expect([
'no-const-assign',
'@typescript-eslint/no-unused-vars',
'vue/multi-word-component-names',
'no-undef',
]).toEqual(rest);
});
test('a vue-tsx project should pass lint', async () => {
const rest = await lintProject('vue-tsx');
expect([
'@typescript-eslint/no-unused-vars',
'vue/multi-word-component-names',
'vue/no-ref-as-operand',
'@typescript-eslint/no-empty-interface',
]).toEqual(rest);
});

View File

@ -0,0 +1,12 @@
import { defineComponent } from 'vue';
export default defineComponent({
name: 'App',
setup() {
return () => (
<>
<h1>App</h1>
</>
);
},
});

View File

@ -0,0 +1,23 @@
import { defineComponent, ref } from 'vue';
import App from './app';
const h2 = 1;
export default defineComponent({
name: 'Index',
setup() {
const count = ref(0);
count++;
count + 1;
1 + count;
return () => (
<>
<h1>About</h1>
<App />
</>
);
},
});

View File

@ -0,0 +1 @@
interface Foo {}

View File

@ -0,0 +1,18 @@
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"strict": true,
"jsx": "preserve",
"importHelpers": true,
"moduleResolution": "node",
"experimentalDecorators": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"baseUrl": ".",
"lib": ["esnext", "dom", "dom.iterable", "scripthost"]
},
"include": ["**/*.ts", "**/*.tsx", "**/*.vue"],
"exclude": ["node_modules"]
}

View File

@ -0,0 +1,20 @@
<template>
<div>
<span v-for="a in arr">{{ a }}</span>
</div>
</template>
<script>
const a = 1;
a = 1;
export default {
name: 'Todo',
data() {
return {
arr: [1, 2, 3],
};
},
};
</script>
<style></style>

View File

@ -0,0 +1,2 @@
const a = b + 1;
export default a;

View File

@ -10,8 +10,12 @@
"resolveJsonModule": true, "resolveJsonModule": true,
"isolatedModules": true, "isolatedModules": true,
"esModuleInterop": true, "esModuleInterop": true,
"lib": ["ESNext", "DOM"], "lib": ["ESNext", "DOM","dom.iterable", "scripthost"],
"skipLibCheck": true "skipLibCheck": true,
"importHelpers": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true
}, },
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"], "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
"references": [{ "path": "./tsconfig.node.json" }] "references": [{ "path": "./tsconfig.node.json" }]

View File

@ -1,9 +1,11 @@
{ {
"compilerOptions": { "compilerOptions": {
"strict": true,
"composite": true, "composite": true,
"module": "ESNext", "module": "ESNext",
"moduleResolution": "Node", "moduleResolution": "Node",
"allowSyntheticDefaultImports": true "allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true
}, },
"include": ["vite.config.ts"] "include": ["vite.config.ts"]
} }

7138
yarn-error.log Normal file

File diff suppressed because it is too large Load Diff

1863
yarn.lock

File diff suppressed because it is too large Load Diff