@schoero/configs 1.4.2 → 1.5.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/eslint/jsx.js +7 -2
- package/eslint/plugins/jsx/index.js +13 -0
- package/eslint/plugins/jsx/no-literals.js +31 -0
- package/eslint/plugins/jsx/wrap-text.js +93 -0
- package/package.json +23 -22
package/eslint/jsx.js
CHANGED
|
@@ -2,16 +2,21 @@ import eslintPluginStylistic from "@stylistic/eslint-plugin";
|
|
|
2
2
|
import eslintPluginTypeScript from "@typescript-eslint/eslint-plugin";
|
|
3
3
|
import eslintParserTypeScript from "@typescript-eslint/parser";
|
|
4
4
|
|
|
5
|
+
import { eslintPluginJsx } from "./plugins/jsx/index.js";
|
|
6
|
+
|
|
5
7
|
|
|
6
8
|
/** @type {import("eslint").Linter.Config[]} */
|
|
7
9
|
export const jsx = [
|
|
8
10
|
{
|
|
9
11
|
files: ["**/*.{jsx,tsx}"],
|
|
10
12
|
plugins: {
|
|
11
|
-
"eslint-plugin-stylistic": eslintPluginStylistic
|
|
13
|
+
"eslint-plugin-stylistic": eslintPluginStylistic,
|
|
14
|
+
"eslint-plugin-jsx": eslintPluginJsx
|
|
12
15
|
},
|
|
13
16
|
rules: {
|
|
14
|
-
"eslint-plugin-stylistic/no-extra-parens": "off"
|
|
17
|
+
"eslint-plugin-stylistic/no-extra-parens": "off",
|
|
18
|
+
"eslint-plugin-jsx/jsx-wrap-text": ["warn", { printWidth: 119 }],
|
|
19
|
+
"eslint-plugin-jsx/jsx-no-literals": "warn"
|
|
15
20
|
}
|
|
16
21
|
},
|
|
17
22
|
{
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsxNoLiterals } from "./no-literals.js";
|
|
2
|
+
import { jsxWrapText } from "./wrap-text.js";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export const eslintPluginJsx = {
|
|
6
|
+
meta: {
|
|
7
|
+
name: "jsx"
|
|
8
|
+
},
|
|
9
|
+
rules: {
|
|
10
|
+
[jsxWrapText.name]: jsxWrapText.rule,
|
|
11
|
+
[jsxNoLiterals.name]: jsxNoLiterals.rule
|
|
12
|
+
}
|
|
13
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export const jsxNoLiterals = {
|
|
2
|
+
rule: {
|
|
3
|
+
type: "layout",
|
|
4
|
+
create: context => {
|
|
5
|
+
return {
|
|
6
|
+
JSXText: node => {
|
|
7
|
+
const trimmed = node.value.replace(/\s+/g, " ").trim();
|
|
8
|
+
if(trimmed.length > 0){
|
|
9
|
+
context.report({
|
|
10
|
+
node,
|
|
11
|
+
messageId: "literalText",
|
|
12
|
+
data: { text: trimmed }
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
},
|
|
19
|
+
meta: {
|
|
20
|
+
type: "problem",
|
|
21
|
+
docs: {
|
|
22
|
+
description: "Disallow literal text in JSX to enforce translation/i18n."
|
|
23
|
+
},
|
|
24
|
+
messages: {
|
|
25
|
+
literalText: "Literal text '{{text}}' found in JSX. Use a translation instead."
|
|
26
|
+
},
|
|
27
|
+
schema: []
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
name: "jsx-no-literals"
|
|
31
|
+
};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
export const jsxWrapText = {
|
|
2
|
+
rule: {
|
|
3
|
+
type: "layout",
|
|
4
|
+
create: context => {
|
|
5
|
+
const { printWidth = 80, indentation = 2 } = context.options[0] || {};
|
|
6
|
+
|
|
7
|
+
return {
|
|
8
|
+
JSXElement: node => {
|
|
9
|
+
for(const child of node.children){
|
|
10
|
+
if(child.type !== "JSXText"){
|
|
11
|
+
continue;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const raw = child.value;
|
|
15
|
+
const startPosition = node.loc.start.column;
|
|
16
|
+
const wrapped = wrapText(raw, printWidth, startPosition, indentation);
|
|
17
|
+
|
|
18
|
+
if(wrapped !== raw){
|
|
19
|
+
context.report({
|
|
20
|
+
node: child,
|
|
21
|
+
message: "JSX text exceeds print width of {{width}} characters.",
|
|
22
|
+
data: { width: printWidth },
|
|
23
|
+
fix(fixer) {
|
|
24
|
+
return fixer.replaceText(child, wrapped);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
},
|
|
32
|
+
meta: {
|
|
33
|
+
docs: {
|
|
34
|
+
description: "Wrap long lines of plain text in JSX according to print width"
|
|
35
|
+
},
|
|
36
|
+
fixable: "whitespace",
|
|
37
|
+
schema: [
|
|
38
|
+
{
|
|
39
|
+
type: "object",
|
|
40
|
+
properties: {
|
|
41
|
+
printWidth: {
|
|
42
|
+
type: "number",
|
|
43
|
+
default: 80
|
|
44
|
+
},
|
|
45
|
+
indentation: {
|
|
46
|
+
type: "number",
|
|
47
|
+
default: 2
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
additionalProperties: false
|
|
51
|
+
}
|
|
52
|
+
]
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
name: "jsx-wrap-text"
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
function wrapText(text, width, start, indentation) {
|
|
60
|
+
const whitespaceOnly = /^\s*$/;
|
|
61
|
+
|
|
62
|
+
if(whitespaceOnly.test(text)){
|
|
63
|
+
return text;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const words = text.trim().split(/\s+/);
|
|
67
|
+
const lines = [];
|
|
68
|
+
let currentLine = "";
|
|
69
|
+
|
|
70
|
+
for(const word of words){
|
|
71
|
+
const nextLine = currentLine ? `${currentLine} ${word}` : word;
|
|
72
|
+
if(start + indentation + nextLine.length > width){
|
|
73
|
+
if(currentLine){lines.push(currentLine);}
|
|
74
|
+
currentLine = word;
|
|
75
|
+
} else {
|
|
76
|
+
currentLine = nextLine;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if(currentLine){
|
|
81
|
+
lines.push(currentLine);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if(lines.length <= 1){
|
|
85
|
+
return text;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return [
|
|
89
|
+
"",
|
|
90
|
+
...lines.map(line => " ".repeat(start + indentation) + line),
|
|
91
|
+
" ".repeat(start)
|
|
92
|
+
].join("\n");
|
|
93
|
+
}
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.
|
|
2
|
+
"version": "1.5.1",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"name": "@schoero/configs",
|
|
5
5
|
"description": "",
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"markdownlint": "markdownlint-cli2 '**/*.md' '#node_modules'",
|
|
26
26
|
"markdownlint:ci": "npm run markdownlint",
|
|
27
27
|
"markdownlint:fix": "npm run markdownlint -- --fix",
|
|
28
|
+
"prepublish": "npm run build",
|
|
28
29
|
"spellcheck": "cspell .",
|
|
29
30
|
"spellcheck:ci": "npm run spellcheck -- --no-progress"
|
|
30
31
|
},
|
|
@@ -39,14 +40,14 @@
|
|
|
39
40
|
"unwritten"
|
|
40
41
|
],
|
|
41
42
|
"peerDependencies": {
|
|
42
|
-
"@stylistic/eslint-plugin": "^4.4.
|
|
43
|
+
"@stylistic/eslint-plugin": "^4.4.1",
|
|
43
44
|
"changelogen": "^0.6.1",
|
|
44
|
-
"cspell": "^9.
|
|
45
|
-
"eslint": "^9.
|
|
45
|
+
"cspell": "^9.1.1",
|
|
46
|
+
"eslint": "^9.29.0",
|
|
46
47
|
"markdownlint": "^0.38.0",
|
|
47
48
|
"unwritten": "^0.2.14",
|
|
48
49
|
"vite": "^6.3.5",
|
|
49
|
-
"vitest": "^3.
|
|
50
|
+
"vitest": "^3.2.3"
|
|
50
51
|
},
|
|
51
52
|
"peerDependenciesMeta": {
|
|
52
53
|
"@stylistic/eslint-plugin": {
|
|
@@ -79,29 +80,29 @@
|
|
|
79
80
|
"@cspell/dict-companies": "^3.2.1",
|
|
80
81
|
"@cspell/dict-css": "^4.0.17",
|
|
81
82
|
"@cspell/dict-de-ch": "^1.3.0",
|
|
82
|
-
"@cspell/dict-en_us": "^4.4.
|
|
83
|
+
"@cspell/dict-en_us": "^4.4.11",
|
|
83
84
|
"@cspell/dict-fr-fr": "^2.3.0",
|
|
84
85
|
"@cspell/dict-fullstack": "^3.2.6",
|
|
85
86
|
"@cspell/dict-html": "^4.0.11",
|
|
86
87
|
"@cspell/dict-html-symbol-entities": "^4.0.3",
|
|
87
88
|
"@cspell/dict-it-it": "^3.1.4",
|
|
88
89
|
"@cspell/dict-lorem-ipsum": "^4.0.4",
|
|
89
|
-
"@cspell/dict-markdown": "^2.0.
|
|
90
|
+
"@cspell/dict-markdown": "^2.0.11",
|
|
90
91
|
"@cspell/dict-node": "^5.0.7",
|
|
91
|
-
"@cspell/dict-npm": "^5.2.
|
|
92
|
+
"@cspell/dict-npm": "^5.2.6",
|
|
92
93
|
"@cspell/dict-public-licenses": "^2.0.13",
|
|
93
|
-
"@cspell/dict-software-terms": "^5.0
|
|
94
|
-
"@cspell/dict-typescript": "^3.2.
|
|
95
|
-
"@stylistic/eslint-plugin": "^4.4.
|
|
96
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
97
|
-
"@typescript-eslint/parser": "^8.
|
|
98
|
-
"cspell-lib": "^9.
|
|
94
|
+
"@cspell/dict-software-terms": "^5.1.0",
|
|
95
|
+
"@cspell/dict-typescript": "^3.2.2",
|
|
96
|
+
"@stylistic/eslint-plugin": "^4.4.1",
|
|
97
|
+
"@typescript-eslint/eslint-plugin": "^8.34.0",
|
|
98
|
+
"@typescript-eslint/parser": "^8.34.0",
|
|
99
|
+
"cspell-lib": "^9.1.1",
|
|
99
100
|
"eslint-plugin-import-newlines": "^1.4.0",
|
|
100
|
-
"eslint-plugin-import-x": "^4.
|
|
101
|
-
"eslint-plugin-jsdoc": "^
|
|
101
|
+
"eslint-plugin-import-x": "^4.15.2",
|
|
102
|
+
"eslint-plugin-jsdoc": "^51.0.1",
|
|
102
103
|
"eslint-plugin-jsonc": "^2.20.1",
|
|
103
104
|
"eslint-plugin-markdown": "^5.1.0",
|
|
104
|
-
"eslint-plugin-perfectionist": "^4.
|
|
105
|
+
"eslint-plugin-perfectionist": "^4.14.0",
|
|
105
106
|
"eslint-plugin-unicorn": "^59.0.1",
|
|
106
107
|
"eslint-plugin-unused-imports": "^4.1.4",
|
|
107
108
|
"eslint-plugin-vitest": "^0.5.4",
|
|
@@ -112,16 +113,16 @@
|
|
|
112
113
|
"yaml-eslint-parser": "^1.3.0"
|
|
113
114
|
},
|
|
114
115
|
"optionalDependencies": {
|
|
115
|
-
"eslint-plugin-better-tailwindcss": "^3.
|
|
116
|
+
"eslint-plugin-better-tailwindcss": "^3.1.0"
|
|
116
117
|
},
|
|
117
118
|
"devDependencies": {
|
|
118
|
-
"@types/node": "^
|
|
119
|
+
"@types/node": "^24.0.1",
|
|
119
120
|
"changelogen": "^0.6.1",
|
|
120
|
-
"cspell": "^9.
|
|
121
|
-
"eslint": "^9.
|
|
121
|
+
"cspell": "^9.1.1",
|
|
122
|
+
"eslint": "^9.29.0",
|
|
122
123
|
"markdownlint": "^0.38.0",
|
|
123
124
|
"vite": "^6.3.5",
|
|
124
|
-
"vitest": "^3.
|
|
125
|
+
"vitest": "^3.2.3"
|
|
125
126
|
},
|
|
126
127
|
"keywords": []
|
|
127
128
|
}
|