@averay/codeformat 0.1.14 → 0.2.1
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/.editorconfig +2 -1
- package/.stylelintignore +1 -0
- package/CODE_OF_CONDUCT.md +83 -0
- package/README.md +6 -8
- package/bin-codeformat.ts +179 -0
- package/eslint.config.js +26 -2
- package/lib/convertWarnsToErrors.ts +43 -0
- package/lib/cssPatterns.ts +7 -0
- package/package.json +40 -47
- package/rulesets/eslint/ruleset-shared.ts +350 -0
- package/rulesets/eslint/ruleset-typescript.ts +239 -0
- package/rulesets/stylelint/ruleset-css.ts +38 -0
- package/rulesets/stylelint/ruleset-scss.ts +32 -0
- package/src/extensions.ts +7 -0
- package/src/index.ts +4 -0
- package/src/makeEslintConfig.ts +98 -0
- package/src/makeStylelintConfig.ts +45 -0
- package/{stylelint.config.cjs → stylelint.config.js} +2 -2
- package/tsconfig.base.json +28 -0
- package/tsconfig.json +10 -0
- package/types.d.ts +97 -0
- package/bin-codeformat.sh +0 -31
- package/dist/codeformat.cjs +0 -792
- package/dist/codeformat.cjs.map +0 -1
- package/dist/codeformat.mjs +0 -753
- package/dist/codeformat.mjs.map +0 -1
- /package/{LICENSE → LICENCE} +0 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/* eslint sort-keys: "error" -- Organise rules */
|
|
2
|
+
|
|
3
|
+
import stylisticPlugin from '@stylistic/eslint-plugin';
|
|
4
|
+
import typescriptPlugin from '@typescript-eslint/eslint-plugin';
|
|
5
|
+
import typescriptParser from '@typescript-eslint/parser';
|
|
6
|
+
import { type TSESLint } from '@typescript-eslint/utils';
|
|
7
|
+
import prettierConfig from 'eslint-config-prettier';
|
|
8
|
+
import eslintCommentsPlugin from 'eslint-plugin-eslint-comments';
|
|
9
|
+
import importPlugin from 'eslint-plugin-import';
|
|
10
|
+
import jsdocPlugin from 'eslint-plugin-jsdoc';
|
|
11
|
+
import promisePlugin from 'eslint-plugin-promise';
|
|
12
|
+
import regexpPlugin from 'eslint-plugin-regexp';
|
|
13
|
+
import sonarjsPlugin from 'eslint-plugin-sonarjs';
|
|
14
|
+
import unicornPlugin from 'eslint-plugin-unicorn';
|
|
15
|
+
|
|
16
|
+
import convertWarnsToErrors from '../lib/convertWarnsToErrors.ts';
|
|
17
|
+
import rulesetEslintShared from '../rulesets/eslint/ruleset-shared.ts';
|
|
18
|
+
import rulesetEslintTypescript, {
|
|
19
|
+
moduleDeclarations as rulesetEslintTypescriptModuleDeclarations,
|
|
20
|
+
} from '../rulesets/eslint/ruleset-typescript.ts';
|
|
21
|
+
|
|
22
|
+
import extensions from './extensions.ts';
|
|
23
|
+
|
|
24
|
+
interface Options {
|
|
25
|
+
/** The ECMA version to use. */
|
|
26
|
+
ecmaVersion?: TSESLint.FlatConfig.EcmaVersion;
|
|
27
|
+
/** The relative path to the project's `tsconfig.json` file. */
|
|
28
|
+
tsconfigPath?: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @param options Project-specific customisations.
|
|
33
|
+
* @returns The complete ESLint config.
|
|
34
|
+
*/
|
|
35
|
+
export default function makeEslintConfig({
|
|
36
|
+
ecmaVersion = 'latest',
|
|
37
|
+
tsconfigPath,
|
|
38
|
+
}: Options = {}): TSESLint.FlatConfig.Config[] {
|
|
39
|
+
return [
|
|
40
|
+
// JavaScript & TypeScript
|
|
41
|
+
{
|
|
42
|
+
files: [`**/*.{${[...extensions.js, ...extensions.ts].join(',')}}`],
|
|
43
|
+
languageOptions: {
|
|
44
|
+
parserOptions: {
|
|
45
|
+
ecmaVersion,
|
|
46
|
+
sourceType: 'module',
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
linterOptions: {
|
|
50
|
+
reportUnusedDisableDirectives: true,
|
|
51
|
+
},
|
|
52
|
+
plugins: {
|
|
53
|
+
'@stylistic': stylisticPlugin,
|
|
54
|
+
'eslint-comments': eslintCommentsPlugin,
|
|
55
|
+
import: importPlugin,
|
|
56
|
+
jsdoc: jsdocPlugin,
|
|
57
|
+
promise: promisePlugin,
|
|
58
|
+
regexp: regexpPlugin,
|
|
59
|
+
sonarjs: sonarjsPlugin,
|
|
60
|
+
unicorn: unicornPlugin,
|
|
61
|
+
},
|
|
62
|
+
rules: convertWarnsToErrors(rulesetEslintShared),
|
|
63
|
+
settings: {
|
|
64
|
+
'import/parsers': {
|
|
65
|
+
espree: extensions.js.map((extension) => `.${extension}`),
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
// TypeScript
|
|
71
|
+
{
|
|
72
|
+
files: [`**/*.{${extensions.ts.join(',')}}`],
|
|
73
|
+
languageOptions: {
|
|
74
|
+
parser: typescriptParser,
|
|
75
|
+
parserOptions: tsconfigPath == null ? {} : { project: tsconfigPath },
|
|
76
|
+
},
|
|
77
|
+
plugins: {
|
|
78
|
+
'@typescript-eslint': typescriptPlugin,
|
|
79
|
+
},
|
|
80
|
+
rules: convertWarnsToErrors(rulesetEslintTypescript),
|
|
81
|
+
settings: {
|
|
82
|
+
...importPlugin.configs.typescript.settings,
|
|
83
|
+
'import/parsers': {
|
|
84
|
+
'@typescript-eslint/parser': extensions.ts.map((extension) => `.${extension}`),
|
|
85
|
+
},
|
|
86
|
+
'import/resolver': {
|
|
87
|
+
'eslint-import-resolver-typescript': tsconfigPath == null ? {} : { project: tsconfigPath },
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
files: ['**/*.d.ts'],
|
|
93
|
+
rules: rulesetEslintTypescriptModuleDeclarations,
|
|
94
|
+
},
|
|
95
|
+
|
|
96
|
+
prettierConfig,
|
|
97
|
+
];
|
|
98
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/* eslint sort-keys: "error" -- Organise rules */
|
|
2
|
+
|
|
3
|
+
import postcssScss from 'postcss-scss';
|
|
4
|
+
import { type Config, type CustomSyntax } from 'stylelint';
|
|
5
|
+
import orderPlugin from 'stylelint-order';
|
|
6
|
+
import scssPlugin from 'stylelint-scss';
|
|
7
|
+
|
|
8
|
+
import rulesetStylelintCss from '../rulesets/stylelint/ruleset-css.ts';
|
|
9
|
+
import rulesetStylelintScss from '../rulesets/stylelint/ruleset-scss.ts';
|
|
10
|
+
|
|
11
|
+
import extensions from './extensions.ts';
|
|
12
|
+
|
|
13
|
+
type ConfigRules = Config['rules'];
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @returns The complete Stylelint config.
|
|
17
|
+
*/
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type,@typescript-eslint/explicit-module-boundary-types -- Preserve specific object shape.
|
|
19
|
+
export default function makeStylelintConfig(cssRules: ConfigRules = {}, scssRules: ConfigRules = {}) {
|
|
20
|
+
return {
|
|
21
|
+
defaultSeverity: 'error',
|
|
22
|
+
ignoreFiles: ['**/*.min.*'],
|
|
23
|
+
plugins: [orderPlugin],
|
|
24
|
+
reportDescriptionlessDisables: true,
|
|
25
|
+
reportInvalidScopeDisables: true,
|
|
26
|
+
reportNeedlessDisables: true,
|
|
27
|
+
rules: {
|
|
28
|
+
...rulesetStylelintCss,
|
|
29
|
+
...cssRules,
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
// eslint-disable-next-line sort-keys -- Logically positioned.
|
|
33
|
+
overrides: [
|
|
34
|
+
{
|
|
35
|
+
customSyntax: postcssScss as unknown as CustomSyntax,
|
|
36
|
+
files: extensions.scss.map((ext) => `**/*.${ext}`), // Does not support glob braces
|
|
37
|
+
plugins: [scssPlugin],
|
|
38
|
+
rules: {
|
|
39
|
+
...rulesetStylelintScss,
|
|
40
|
+
...scssRules,
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
} satisfies Config;
|
|
45
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint import/no-commonjs: "off" -- Unsupported by Stylelint */
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import { makeStylelintConfig } from './src/index.ts';
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
export default {
|
|
6
6
|
...makeStylelintConfig(),
|
|
7
7
|
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
// Output
|
|
4
|
+
"noEmit": true,
|
|
5
|
+
// Module resolution
|
|
6
|
+
"allowImportingTsExtensions": true,
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
"forceConsistentCasingInFileNames": true,
|
|
9
|
+
"isolatedModules": true,
|
|
10
|
+
"module": "ESNext",
|
|
11
|
+
"moduleResolution": "Bundler",
|
|
12
|
+
"resolveJsonModule": true,
|
|
13
|
+
// Type checking
|
|
14
|
+
"allowJs": true,
|
|
15
|
+
"allowUnreachableCode": false,
|
|
16
|
+
"allowUnusedLabels": false,
|
|
17
|
+
"checkJs": true,
|
|
18
|
+
"exactOptionalPropertyTypes": false,
|
|
19
|
+
"noImplicitOverride": true,
|
|
20
|
+
"noImplicitReturns": true,
|
|
21
|
+
"noPropertyAccessFromIndexSignature": true,
|
|
22
|
+
"noUncheckedIndexedAccess": true,
|
|
23
|
+
"noUnusedLocals": true,
|
|
24
|
+
"noUnusedParameters": true,
|
|
25
|
+
"skipLibCheck": true,
|
|
26
|
+
"strict": true
|
|
27
|
+
}
|
|
28
|
+
}
|
package/tsconfig.json
ADDED
package/types.d.ts
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
declare module '@stylistic/eslint-plugin' {
|
|
2
|
+
import { type TSESLint } from '@typescript-eslint/utils';
|
|
3
|
+
|
|
4
|
+
export default {} as TSESLint.FlatConfig.Plugin & {
|
|
5
|
+
configs: Record<'recommended-flat', TSESLint.FlatConfig.Config>;
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
declare module 'eslint-config-prettier' {
|
|
10
|
+
import { type TSESLint } from '@typescript-eslint/utils';
|
|
11
|
+
|
|
12
|
+
export default {} as TSESLint.FlatConfig.Config;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
declare module 'eslint-plugin-eslint-comments' {
|
|
16
|
+
import { type TSESLint } from '@typescript-eslint/utils';
|
|
17
|
+
|
|
18
|
+
export default {} as TSESLint.FlatConfig.Plugin & {
|
|
19
|
+
configs: Record<'recommended', TSESLint.FlatConfig.Config>;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
declare module 'eslint-plugin-import' {
|
|
24
|
+
import { type TSESLint } from '@typescript-eslint/utils';
|
|
25
|
+
|
|
26
|
+
export default {} as TSESLint.FlatConfig.Plugin & {
|
|
27
|
+
configs: Record<'recommended' | 'react' | 'react-native' | 'electron' | 'typescript', TSESLint.FlatConfig.Config>;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
declare module 'eslint-plugin-jsdoc' {
|
|
32
|
+
import { type TSESLint } from '@typescript-eslint/utils';
|
|
33
|
+
|
|
34
|
+
export default {} as TSESLint.FlatConfig.Plugin & {
|
|
35
|
+
configs: Record<'recommended', TSESLint.FlatConfig.Config>;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
declare module 'eslint-plugin-promise' {
|
|
40
|
+
import { type TSESLint } from '@typescript-eslint/utils';
|
|
41
|
+
|
|
42
|
+
export default {} as TSESLint.FlatConfig.Plugin & {
|
|
43
|
+
configs: Record<'recommended', TSESLint.FlatConfig.Config>;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
declare module 'eslint-plugin-sonarjs' {
|
|
48
|
+
import { type TSESLint } from '@typescript-eslint/utils';
|
|
49
|
+
|
|
50
|
+
export default {} as TSESLint.FlatConfig.Plugin & {
|
|
51
|
+
configs: Record<'recommended', TSESLint.FlatConfig.Config>;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
declare module 'eslint-plugin-unicorn' {
|
|
56
|
+
import { type TSESLint } from '@typescript-eslint/utils';
|
|
57
|
+
|
|
58
|
+
export default {} as TSESLint.FlatConfig.Plugin & {
|
|
59
|
+
configs: Record<'recommended', TSESLint.FlatConfig.Config>;
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
declare module 'stylelint-config-recommended' {
|
|
64
|
+
import { type Config } from 'stylelint';
|
|
65
|
+
|
|
66
|
+
export default {} as Config;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
declare module 'stylelint-config-recommended-scss' {
|
|
70
|
+
import { type Config } from 'stylelint';
|
|
71
|
+
|
|
72
|
+
export default {} as Config;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
declare module 'stylelint-config-standard' {
|
|
76
|
+
import { type Config } from 'stylelint';
|
|
77
|
+
|
|
78
|
+
export default {} as Config;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
declare module 'stylelint-config-standard-scss' {
|
|
82
|
+
import { type Config } from 'stylelint';
|
|
83
|
+
|
|
84
|
+
export default {} as Config;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
declare module 'stylelint-order' {
|
|
88
|
+
import { type Plugin } from 'stylelint';
|
|
89
|
+
|
|
90
|
+
export default {} as Plugin;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
declare module 'stylelint-scss' {
|
|
94
|
+
import { type Plugin } from 'stylelint';
|
|
95
|
+
|
|
96
|
+
export default {} as Plugin;
|
|
97
|
+
}
|
package/bin-codeformat.sh
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
#!/bin/sh
|
|
2
|
-
|
|
3
|
-
set -e
|
|
4
|
-
|
|
5
|
-
# Parse arguments
|
|
6
|
-
ACTION="$1"
|
|
7
|
-
DIR="$2"
|
|
8
|
-
if [ "$DIR" = '' ]; then
|
|
9
|
-
DIR='.'
|
|
10
|
-
fi
|
|
11
|
-
|
|
12
|
-
CONFIG_PATH_TYPESCRIPT="$DIR/tsconfig.json"
|
|
13
|
-
|
|
14
|
-
if [ "$ACTION" = 'check' ]; then
|
|
15
|
-
npx prettier --check "$DIR"
|
|
16
|
-
npx eslint "$DIR"
|
|
17
|
-
if [ -f "$CONFIG_PATH_TYPESCRIPT" ]; then
|
|
18
|
-
npx tsc --noEmit --project "$DIR/tsconfig.json"
|
|
19
|
-
fi
|
|
20
|
-
npx stylelint --allow-empty-input "$DIR/**/*.{css,sass,scss}"
|
|
21
|
-
elif [ "$ACTION" = 'fix' ]; then
|
|
22
|
-
npx prettier --write "$DIR"
|
|
23
|
-
npx eslint --fix "$DIR"
|
|
24
|
-
npx stylelint --fix --allow-empty-input "$DIR/**/*.{css,sass,scss}"
|
|
25
|
-
else
|
|
26
|
-
# Invalid/unset arguments
|
|
27
|
-
echo "Usage:
|
|
28
|
-
$0 check [root-path]
|
|
29
|
-
$0 fix [root-path]" >&2
|
|
30
|
-
exit 1
|
|
31
|
-
fi
|