@qlover/fe-standard 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/config/jest.esm.js +19 -0
- package/config/prettierrc.js +7 -0
- package/config/tsconfig.base.json +18 -0
- package/eslint/chain.js +90 -0
- package/eslint/index.js +1 -0
- package/eslint/ts.rules.js +22 -0
- package/package.json +52 -0
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** @type {import('jest').Config} */
|
|
2
|
+
export default {
|
|
3
|
+
injectGlobals: true,
|
|
4
|
+
preset: 'ts-jest',
|
|
5
|
+
testEnvironment: 'node',
|
|
6
|
+
extensionsToTreatAsEsm: ['.ts'],
|
|
7
|
+
moduleNameMapper: {
|
|
8
|
+
'^(\\.{1,2}/.*)\\.js$': '$1'
|
|
9
|
+
},
|
|
10
|
+
transform: {
|
|
11
|
+
'^.+\\.tsx?$': [
|
|
12
|
+
'ts-jest',
|
|
13
|
+
{
|
|
14
|
+
useESM: true
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
},
|
|
18
|
+
testMatch: ['**/__tests__/**/*.[jt]s?(x)', '!**/__tests__/helpers/**']
|
|
19
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"allowJs": true,
|
|
4
|
+
"baseUrl": ".",
|
|
5
|
+
"target": "ESNEXT",
|
|
6
|
+
"module": "ESNext",
|
|
7
|
+
"lib": ["ESNext", "DOM"],
|
|
8
|
+
"outDir": "dist",
|
|
9
|
+
"sourceMap": true,
|
|
10
|
+
"declaration": true,
|
|
11
|
+
"declarationDir": "dist/types",
|
|
12
|
+
"strict": true,
|
|
13
|
+
"esModuleInterop": true,
|
|
14
|
+
"skipLibCheck": true,
|
|
15
|
+
"forceConsistentCasingInFileNames": true,
|
|
16
|
+
"moduleResolution": "Node"
|
|
17
|
+
}
|
|
18
|
+
}
|
package/eslint/chain.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import tslint from 'typescript-eslint';
|
|
2
|
+
import prettier from 'eslint-plugin-prettier';
|
|
3
|
+
import lodash from 'lodash';
|
|
4
|
+
import tsRules from './ts.rules.js';
|
|
5
|
+
import js from '@eslint/js';
|
|
6
|
+
import prettierConfig from '../config/prettierrc.js';
|
|
7
|
+
const { merge } = lodash;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Create typescript recommended config.
|
|
11
|
+
*
|
|
12
|
+
* @param {string[]} files
|
|
13
|
+
* @returns {import('eslint').Linter.Config}
|
|
14
|
+
*/
|
|
15
|
+
export function createTslintRecommended(files) {
|
|
16
|
+
let result = {};
|
|
17
|
+
tslint.configs.recommended.forEach((config) => {
|
|
18
|
+
result = merge(result, config);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
if (files) {
|
|
22
|
+
result.files = files;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// merge ts rules
|
|
26
|
+
result.rules = {
|
|
27
|
+
...result.rules,
|
|
28
|
+
...tsRules
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Create a common config.
|
|
36
|
+
*
|
|
37
|
+
* default config for js and ts.
|
|
38
|
+
*
|
|
39
|
+
*
|
|
40
|
+
* @param {string[]} files
|
|
41
|
+
* @returns {import('eslint').Linter.Config}
|
|
42
|
+
*/
|
|
43
|
+
export function createCommon(files) {
|
|
44
|
+
return {
|
|
45
|
+
files: files || ['**/*.js', '**/*.ts'],
|
|
46
|
+
languageOptions: {
|
|
47
|
+
globals: {
|
|
48
|
+
process: true,
|
|
49
|
+
console: true
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
plugins: {
|
|
53
|
+
prettier: prettier
|
|
54
|
+
},
|
|
55
|
+
rules: {
|
|
56
|
+
// TODO: import
|
|
57
|
+
...js.configs.recommended.rules,
|
|
58
|
+
'prettier/prettier': ['error', prettierConfig],
|
|
59
|
+
'spaced-comment': 'error'
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Add no-restricted-globals rule for browser environment.
|
|
66
|
+
*
|
|
67
|
+
* @param {import('eslint').Linter.Config} options
|
|
68
|
+
* @returns {import('eslint').Linter.Config}
|
|
69
|
+
*/
|
|
70
|
+
export function chainEnv(options) {
|
|
71
|
+
const { allGlobals, ...config } = options;
|
|
72
|
+
const globals = config.languageOptions.globals;
|
|
73
|
+
|
|
74
|
+
if (globals) {
|
|
75
|
+
const allGlobalKeys = new Set([...Object.keys(allGlobals)]);
|
|
76
|
+
const notAllowedGlobals = Array.from(allGlobalKeys).filter((key) => {
|
|
77
|
+
return !(key in globals) || globals[key] == null;
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
return {
|
|
81
|
+
...config,
|
|
82
|
+
rules: {
|
|
83
|
+
...config.rules,
|
|
84
|
+
'no-restricted-globals': ['error', ...notAllowedGlobals]
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return config;
|
|
90
|
+
}
|
package/eslint/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './chain.js';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** @type {import('eslint').Linter.Config} */
|
|
2
|
+
export default {
|
|
3
|
+
// force function return type
|
|
4
|
+
'@typescript-eslint/explicit-function-return-type': 'error',
|
|
5
|
+
// not use any
|
|
6
|
+
'@typescript-eslint/no-explicit-any': 'error',
|
|
7
|
+
// allow ts-comment
|
|
8
|
+
'@typescript-eslint/ban-ts-comment': 'off',
|
|
9
|
+
// allow empty object type
|
|
10
|
+
'@typescript-eslint/no-empty-object-type': 'off',
|
|
11
|
+
// not allow unused vars
|
|
12
|
+
'@typescript-eslint/no-unused-vars': [
|
|
13
|
+
'error',
|
|
14
|
+
{
|
|
15
|
+
vars: 'all',
|
|
16
|
+
args: 'none',
|
|
17
|
+
ignoreRestSiblings: true,
|
|
18
|
+
varsIgnorePattern: '^_',
|
|
19
|
+
caughtErrors: 'none'
|
|
20
|
+
}
|
|
21
|
+
]
|
|
22
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@qlover/fe-standard",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"files": [
|
|
7
|
+
"config",
|
|
8
|
+
"eslint",
|
|
9
|
+
"package.json",
|
|
10
|
+
"README.md"
|
|
11
|
+
],
|
|
12
|
+
"exports": {
|
|
13
|
+
"./config/*": "./config/*",
|
|
14
|
+
"./eslint/*": "./eslint/*",
|
|
15
|
+
"./package.json": "./package.json"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/qlover/fe-base.git",
|
|
20
|
+
"directory": "packages/fe-standard"
|
|
21
|
+
},
|
|
22
|
+
"homepage": "https://github.com/qlover/fe-base/blob/master/packages/fe-standard/README.md",
|
|
23
|
+
"keywords": [
|
|
24
|
+
"config",
|
|
25
|
+
"standard",
|
|
26
|
+
"fe-standard",
|
|
27
|
+
"eslint-config"
|
|
28
|
+
],
|
|
29
|
+
"author": "qlover",
|
|
30
|
+
"license": "ISC",
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@eslint/js": "^9.13.0",
|
|
36
|
+
"@typescript-eslint/eslint-plugin": "^8.12.0",
|
|
37
|
+
"@typescript-eslint/parser": "^8.12.0",
|
|
38
|
+
"eslint": "^9.13.0",
|
|
39
|
+
"eslint-config-prettier": "^9.1.0",
|
|
40
|
+
"eslint-plugin-import": "^2.31.0",
|
|
41
|
+
"eslint-plugin-jest": "^28.8.3",
|
|
42
|
+
"eslint-plugin-n": "^17.11.1",
|
|
43
|
+
"eslint-plugin-prettier": "^5.2.1",
|
|
44
|
+
"eslint-plugin-promise": "^7.1.0",
|
|
45
|
+
"eslint-plugin-unused-imports": "^4.1.4",
|
|
46
|
+
"globals": "^15.11.0",
|
|
47
|
+
"prettier": "^3.3.3",
|
|
48
|
+
"ts-jest": "^29.2.5",
|
|
49
|
+
"typescript": "~5.4.0",
|
|
50
|
+
"typescript-eslint": "^8.18.0"
|
|
51
|
+
}
|
|
52
|
+
}
|