Skip to content

Commit 5a2e453

Browse files
authored
build: harden linter settings (#2346)
1 parent edf343c commit 5a2e453

File tree

19 files changed

+744
-437
lines changed

19 files changed

+744
-437
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
site/resources

.eslintrc

Lines changed: 130 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"root": true,
23
"env": {
34
"browser": true,
45
"node": true,
@@ -13,10 +14,137 @@
1314
"func-call-spacing": ["warn", "never"],
1415
"indent": ["warn", "tab", { "ignoredNodes": ["TemplateLiteral *"] }],
1516
"linebreak-style": ["warn", "unix"],
16-
"no-console": 0,
17+
"no-console": ["warn", { "allow": ["warn", "error"] }],
1718
"quotes": ["warn", "double"],
1819
"semi": ["warn", "always"],
1920
"space-before-blocks": ["warn", "always"]
2021
},
21-
"root": true
22+
"overrides": [
23+
{
24+
"files": ["*.json"],
25+
"parser": "jsonc-eslint-parser",
26+
"extends": ["plugin:jsonc/recommended-with-jsonc"],
27+
"rules": {
28+
"jsonc/sort-keys": [
29+
"warn",
30+
{
31+
"pathPattern": ".*", // Hits the all properties
32+
"hasProperties": ["type"],
33+
"order": [
34+
"type",
35+
"properties",
36+
"items",
37+
"required",
38+
"minItems",
39+
"additionalProperties",
40+
"additionalItems"
41+
]
42+
},
43+
{
44+
"pathPattern": ".*",
45+
"order": { "type": "asc" }
46+
}
47+
]
48+
}
49+
},
50+
{
51+
"files": ["project.json"],
52+
"rules": {
53+
"jsonc/sort-keys": [
54+
"warn",
55+
{
56+
"pathPattern": "^$",
57+
"order": [
58+
"$schema",
59+
"name",
60+
"tags",
61+
"implicitDependencies",
62+
"targets"
63+
]
64+
},
65+
{
66+
"pathPattern": ".*",
67+
"order": { "type": "asc" }
68+
}
69+
]
70+
}
71+
},
72+
{
73+
"files": ["package.json"],
74+
"rules": {
75+
"jsonc/sort-keys": [
76+
"warn",
77+
{
78+
"pathPattern": "^$",
79+
"order": [
80+
"$schema",
81+
"private",
82+
"name",
83+
"version",
84+
"description",
85+
"license",
86+
"author",
87+
"maintainers",
88+
"contributors",
89+
"homepage",
90+
"repository",
91+
"bugs",
92+
"type",
93+
"exports",
94+
"main",
95+
"module",
96+
"browser",
97+
"man",
98+
"preferGlobal",
99+
"bin",
100+
"files",
101+
"directories",
102+
"scripts",
103+
"config",
104+
"sideEffects",
105+
"types",
106+
"typings",
107+
"workspaces",
108+
"resolutions",
109+
"dependencies",
110+
"bundleDependencies",
111+
"bundledDependencies",
112+
"peerDependencies",
113+
"peerDependenciesMeta",
114+
"optionalDependencies",
115+
"devDependencies",
116+
"keywords",
117+
"engines",
118+
"engineStrict",
119+
"os",
120+
"cpu",
121+
"publishConfig"
122+
]
123+
},
124+
{
125+
"pathPattern": "^repository$",
126+
"order": ["type", "url", "directory"]
127+
},
128+
{
129+
"pathPattern": ".*",
130+
"order": { "type": "asc" }
131+
}
132+
]
133+
}
134+
},
135+
{
136+
"files": [
137+
"components/*/stories/*.js",
138+
".storybook/*.js",
139+
".storybook/**/*.js"
140+
],
141+
"parserOptions": {
142+
"ecmaVersion": "latest",
143+
"sourceType": "module",
144+
"ecmaFeatures": {
145+
"impliedStrict": true
146+
}
147+
}
148+
}
149+
]
22150
}

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package-lock.json
2020

2121
# Storybook build output
2222
.storybook/storybook-static
23+
storybook-static
2324
build-storybook.log
2425

2526
# Chromatic
@@ -30,3 +31,6 @@ chromatic.config.json
3031

3132
# Custom diff tool
3233
.diff-output
34+
35+
.eslintcache
36+
.stylelintcache

.prettierignore

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
1+
# Tooling config files
12
**/.git
23
**/.svn
34
**/.hg
45
**/node_modules
56

6-
components/*/dist
7+
# Static utility assets
78
tokens/custom-*/*.css
8-
.storybook/storybook-static/**
9-
generator
9+
site/includes/*.js
10+
11+
# Compiled and generated files
1012
dist
11-
*.hbs
13+
.storybook/storybook-static
14+
*-generated.css
1215

13-
site/includes/*.js
16+
# Template files
17+
*.hbs
1418

19+
# OS generated files
1520
.DS_Store*
1621
ehthumbs.db
1722
Icon?

.stylelintignore

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
# Static utility assets
2+
tokens/custom-*/*.css
3+
generator
4+
5+
# Compiled and generated files
6+
dist
7+
.storybook/storybook-static
18
*-generated.css
29

3-
tokens/**/*.css
410
node_modules/**/*.css
5-
611
plugins/*/expected/*
7-
plugins/*/fixtures/*
8-
dist/*
9-
10-
components/*/dist/*
11-
components/*/node_modules/*
12+
plugins/*/fixtures/*

nx.json

Lines changed: 56 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@
1616
"core": ["{projectRoot}/*.css", "{projectRoot}/themes/*.css"],
1717
"scripts": ["{projectRoot}/stories/*.js"],
1818
"docs": ["{projectRoot}/metadata/*.yml"],
19+
"stylelint": [
20+
"{workspaceRoot}/.stylelintignore",
21+
"{workspaceRoot}/stylelint.config.js",
22+
"{workspaceRoot}/plugins/stylelint-*/index.js"
23+
],
24+
"eslint": ["{workspaceRoot}/.eslintrc.js"],
25+
"prettier": ["{workspaceRoot}/.prettierrc"],
1926
"tools": [
2027
"{projectRoot}/*.json",
2128
"{workspaceRoot}/postcss.config.js",
@@ -25,7 +32,13 @@
2532
"targetDefaults": {
2633
"clean": {
2734
"cache": true,
28-
"inputs": ["{projectRoot}/dist", { "externalDependencies": ["rimraf"] }],
35+
"inputs": [
36+
"{projectRoot}/dist/*.{css,json}",
37+
"{projectRoot}/dist/**/*.{css,json}",
38+
"{projectRoot}/dist/*.map",
39+
"{projectRoot}/dist/**/*.map",
40+
{ "externalDependencies": ["rimraf"] }
41+
],
2942
"outputs": [],
3043
"executor": "nx:run-commands",
3144
"options": {
@@ -50,13 +63,18 @@
5063
{ "externalDependencies": ["postcss"] },
5164
{ "env": "NODE_ENV" }
5265
],
53-
"outputs": ["{projectRoot}/dist", "{projectRoot}/metadata/mods.md"],
66+
"outputs": [
67+
"{projectRoot}/dist/*.{css,json}",
68+
"{projectRoot}/dist/themes/*.css",
69+
"{projectRoot}/dist/*.map",
70+
"{projectRoot}/dist/themes/*.css.map",
71+
"{projectRoot}/metadata/mods.md"
72+
],
5473
"executor": "nx:run-commands",
5574
"options": {
5675
"commands": [
5776
"node -e 'require(\"./tasks/component-builder.js\").default()'"
58-
],
59-
"parallel": false
77+
]
6078
}
6179
},
6280
"compare": {
@@ -90,35 +108,39 @@
90108
}
91109
},
92110
"lint": {
93-
"inputs": ["core", { "externalDependencies": ["stylelint", "eslint"] }],
111+
"cache": true,
112+
"inputs": [
113+
"core",
114+
"scripts",
115+
"stylelint",
116+
"eslint",
117+
"prettier",
118+
{ "externalDependencies": ["stylelint", "eslint", "prettier"] }
119+
],
94120
"executor": "nx:run-commands",
95121
"options": {
96122
"commands": [
97-
"stylelint {projectRoot}/*.css {projectRoot}/themes/*.css",
98-
"eslint {projectRoot}/stories/*.js"
123+
"stylelint --cache --allow-empty-input --report-descriptionless-disables --report-invalid-scope-disables --report-needless-disables {projectRoot}/*.css {projectRoot}/**/*.css --ignore-pattern {projectRoot}/dist",
124+
"eslint --cache --no-error-on-unmatched-pattern --report-unused-disable-directives {projectRoot}/*.{js,json} {projectRoot}/**/*.{js,json} --ignore-pattern {projectRoot}/dist || exit 0"
99125
]
100126
}
101127
},
102128
"format": {
103-
"inputs": ["core", { "externalDependencies": ["stylelint", "eslint"] }],
104-
"executor": "nx:run-commands",
105-
"options": {
106-
"commands": [
107-
"stylelint --fix {projectRoot}/*.css {projectRoot}/themes/*.css",
108-
"eslint --fix --no-error-on-unmatched-pattern {projectRoot}/stories/*.js"
109-
]
110-
}
111-
},
112-
"validate": {
129+
"cache": true,
113130
"inputs": [
114-
"{workspaceRoot}/schemas/documentation.schema.json",
115-
"docs",
116-
{ "externalDependencies": ["pajv"] }
131+
"core",
132+
"scripts",
133+
"stylelint",
134+
"eslint",
135+
"prettier",
136+
{ "externalDependencies": ["stylelint", "eslint", "prettier"] }
117137
],
118138
"executor": "nx:run-commands",
119139
"options": {
120140
"commands": [
121-
"test -e {projectRoot}/metadata && pajv validate -s ./schemas/documentation.schema.json -d \"{projectRoot}/metadata/*.yml\" || exit 0"
141+
"stylelint --fix --cache --allow-empty-input --quiet {projectRoot}/*.css {projectRoot}/**/*.css",
142+
"eslint --fix --cache --no-error-on-unmatched-pattern --quiet {projectRoot}/*.json {projectRoot}/stories/*.js || exit 0",
143+
"prettier --write --cache --loglevel error --ignore-unknown --no-error-on-unmatched-pattern {projectRoot}/*.{yml,md} {projectRoot}/**/*.{yml,md}"
122144
]
123145
}
124146
},
@@ -139,7 +161,6 @@
139161
]
140162
},
141163
"plugins": {
142-
"dependsOn": [],
143164
"inputs": [
144165
"{projectRoot}/index.js",
145166
"{projectRoot}/test.js",
@@ -150,6 +171,19 @@
150171
"commands": ["ava test.js"]
151172
}
152173
}
174+
},
175+
"validate": {
176+
"inputs": [
177+
"{workspaceRoot}/schemas/documentation.schema.json",
178+
"docs",
179+
{ "externalDependencies": ["pajv"] }
180+
],
181+
"executor": "nx:run-commands",
182+
"options": {
183+
"commands": [
184+
"test -e {projectRoot}/metadata && pajv validate -s ./schemas/documentation.schema.json -d \"{projectRoot}/metadata/*.yml\" || exit 0"
185+
]
186+
}
153187
}
154188
}
155189
}

package.json

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"compare": "cross-env NODE_ENV=production node ./tasks/compare-compiled-output.js",
2828
"dev": "cross-env NODE_ENV=production nx run storybook:build:docs && nx start docs",
2929
"format": "yarn formatter tag:component",
30-
"formatter": "nx run-many --target format --verbose --projects",
30+
"formatter": "nx run-many --target format --projects",
3131
"preinstall": "command -v nvm >/dev/null 2>&1 && nvm use || exit 0",
3232
"lint": "yarn linter tag:component",
3333
"linter": "nx run-many --target lint --verbose --projects",
@@ -73,9 +73,12 @@
7373
"diff": "^5.1.0",
7474
"diff2html": "^3.4.45",
7575
"eslint": "^8.57.0",
76+
"eslint-plugin-jsonc": "^2.13.0",
77+
"eslint-plugin-prettier": "^5.1.3",
7678
"fast-glob": "^3.3.2",
7779
"gh-pages": "^6.1.1",
7880
"husky": "^9.0.11",
81+
"jsonc-eslint-parser": "^2.4.0",
7982
"lerna": "^6.6.2",
8083
"lint-staged": "^15.2.2",
8184
"lodash": "^4.17.21",
@@ -123,11 +126,27 @@
123126
"package.json": [
124127
"prettier-package-json --write"
125128
],
129+
"components/*/*.css": [
130+
"stylelint --fix --cache --allow-empty-input --quiet"
131+
],
132+
"*.json": [
133+
"eslint --fix --cache --no-error-on-unmatched-pattern --quiet"
134+
],
135+
"components/*/stories/*.js": [
136+
"eslint --fix --cache --no-error-on-unmatched-pattern --quiet"
137+
],
138+
"plugins/*/*.js": [
139+
"eslint --fix --cache --no-error-on-unmatched-pattern --quiet"
140+
],
126141
"dist/*.css": [
127142
"prettier --no-config --no-error-on-unmatched-pattern --ignore-unknown --loglevel silent --write"
128143
],
129144
"components/*/metadata/*.{yml,yaml}": [
130-
"pajv test --valid -s ./schemas/documentation.schema.json -d "
145+
"pajv test --valid -s ./schemas/documentation.schema.json -d ",
146+
"prettier --no-config --no-error-on-unmatched-pattern --ignore-unknown --loglevel silent --write"
147+
],
148+
"*.md": [
149+
"prettier --no-config --no-error-on-unmatched-pattern --ignore-unknown --loglevel silent --write"
131150
]
132151
}
133152
}

0 commit comments

Comments
 (0)