Skip to content

Commit ac0533d

Browse files
authored
Add support for postcss, babel, scss, sass, less, and stylus to rules that use compilation. (#141)
* Supports lang="postcss" * update * update * update * update * update * update * Support babel * update * update * support sass * support less * Support stylus * fix * update
1 parent 6ad3b06 commit ac0533d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1588
-605
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
/tests/fixtures/rules/indent/invalid/ts
1111
/tests/fixtures/rules/indent/invalid/ts-v5
1212
/tests/fixtures/rules/valid-compile/invalid/ts
13+
/tests/fixtures/rules/valid-compile/valid/babel
1314
/tests/fixtures/rules/valid-compile/valid/ts
1415
/tests/fixtures/rules/prefer-style-directive
1516
/.svelte-kit

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ You can change the behavior of this plugin with some settings.
179179

180180
- `ignoreWarnings` (optional) ... Specifies an array of rules that ignore reports in the template.
181181
For example, set rules on the template that cannot avoid false positives.
182+
- `compileOptions` (optional) ... Specifies options for Svelte compile. Effects rules that use Svelte compile. The target rules are [@ota-meshi/svelte/valid-compile](https://ota-meshi.github.io/eslint-plugin-svelte/rules/valid-compile/) and [@ota-meshi/svelte/no-unused-svelte-ignore](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-unused-svelte-ignore/). **Note that it has no effect on ESLint's custom parser**.
183+
- `postcss` (optional) ... Specifies options related to PostCSS. You can disable the PostCSS process by specifying `false`.
184+
- `configFilePath` (optional) ... Specifies the path of the directory containing the PostCSS configuration.
182185

183186
e.g.
184187

@@ -191,6 +194,11 @@ module.exports = {
191194
"@typescript-eslint/no-unsafe-assignment",
192195
"@typescript-eslint/no-unsafe-member-access",
193196
],
197+
compileOptions: {
198+
postcss: {
199+
configFilePath: "./path/to/my/postcss.config.js",
200+
},
201+
},
194202
},
195203
},
196204
// ...

babel.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"use strict"
2+
3+
// for test
4+
module.exports = {
5+
plugins: ["@babel/plugin-proposal-function-bind"],
6+
}

docs-svelte-kit/build-system/build.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@ function bundle(entryPoint, externals) {
3030
bundle: true,
3131
external: externals,
3232
write: false,
33+
inject: [require.resolve("./src/process-shim.mjs")],
3334
})
3435

3536
return `${result.outputFiles[0].text}`
3637
}
3738

3839
/** transform code */
3940
function transform(code, injects) {
41+
const newCode = code.replace(/"[a-z]+" = "[a-z]+";/, "")
4042
// const newCode = babelCore.transformSync(code, {
4143
// babelrc: false,
4244
// plugins: [
@@ -57,18 +59,17 @@ function transform(code, injects) {
5759
// })
5860
return `
5961
${injects
60-
.map((inject) => `import $inject_${inject}$ from '${inject}';`)
62+
.map(
63+
(inject) =>
64+
`import $inject_${inject.replace(/-/g, "_")}$ from '${inject}';`,
65+
)
6166
.join("\n")}
6267
const $_injects_$ = {${injects
63-
.map((inject) => `${inject}:$inject_${inject}$`)
68+
.map((inject) => `${inject.replace(/-/g, "_")}:$inject_${inject}$`)
6469
.join(",\n")}};
65-
const process = {
66-
env: {},
67-
cwd: () => undefined,
68-
}
6970
function require(module, ...args) {
7071
return $_injects_$[module] || {}
7172
}
72-
${code}
73+
${newCode}
7374
`
7475
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export let process = {
2+
env: {},
3+
cwd: () => "",
4+
}

docs-svelte-kit/shim/path.mjs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,17 @@ function extname(p) {
88
return /\.[\w$-]+$/iu.exec(p)[0]
99
}
1010

11-
const posix = { dirname, extname }
11+
function relative(s) {
12+
return s
13+
}
14+
15+
function resolve(s) {
16+
return s
17+
}
18+
19+
const sep = "/"
20+
21+
const posix = { dirname, extname, resolve, relative, sep }
1222
posix.posix = posix
13-
export { dirname, extname, posix }
23+
export { dirname, extname, posix, resolve, relative, sep }
1424
export default posix
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* eslint require-jsdoc:0 -- shim */
2+
import nested from "postcss-nested"
3+
4+
function loadConfig() {
5+
// noop
6+
}
7+
8+
export function sync(options) {
9+
return {
10+
plugins: [nested],
11+
options,
12+
}
13+
}
14+
15+
loadConfig.sync = sync
16+
17+
export default loadConfig

docs/user-guide.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ You can change the behavior of this plugin with some settings.
141141

142142
- `ignoreWarnings` (optional) ... Specifies an array of rules that ignore reports in the template.
143143
For example, set rules on the template that cannot avoid false positives.
144+
- `compileOptions` (optional) ... Specifies options for Svelte compile. Effects rules that use Svelte compile. The target rules are [@ota-meshi/svelte/valid-compile](./rules/valid-compile.md) and [@ota-meshi/svelte/no-unused-svelte-ignore](./rules/no-unused-svelte-ignore.md). **Note that it has no effect on ESLint's custom parser**.
145+
- `postcss` (optional) ... Specifies options related to PostCSS. You can disable the PostCSS process by specifying `false`.
146+
- `configFilePath` (optional) ... Specifies the path of the directory containing the PostCSS configuration.
144147

145148
e.g.
146149

@@ -153,6 +156,11 @@ module.exports = {
153156
"@typescript-eslint/no-unsafe-assignment",
154157
"@typescript-eslint/no-unsafe-member-access",
155158
],
159+
compileOptions: {
160+
postcss: {
161+
configFilePath: "./path/to/my/postcss.config.js",
162+
},
163+
},
156164
},
157165
},
158166
// ...

package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"eslint-utils": "^3.0.0",
5959
"known-css-properties": "^0.25.0",
6060
"postcss": "^8.4.5",
61+
"postcss-load-config": "^3.1.4",
6162
"postcss-safe-parser": "^6.0.0",
6263
"sourcemap-codec": "^1.4.8",
6364
"svelte-eslint-parser": "^0.16.0"
@@ -73,20 +74,25 @@
7374
},
7475
"devDependencies": {
7576
"@babel/core": "^7.16.0",
77+
"@babel/eslint-parser": "^7.17.0",
78+
"@babel/plugin-proposal-function-bind": "^7.16.7",
7679
"@babel/types": "^7.16.0",
7780
"@fontsource/fira-mono": "^4.5.0",
7881
"@ota-meshi/eslint-plugin": "^0.10.0",
7982
"@ota-meshi/eslint-plugin-svelte": "^0.33.0",
8083
"@sindresorhus/slugify": "^2.1.0",
8184
"@sveltejs/adapter-static": "^1.0.0-next.26",
8285
"@sveltejs/kit": "^1.0.0-next.240",
86+
"@types/babel__core": "^7.1.19",
8387
"@types/eslint": "^8.0.0",
8488
"@types/eslint-scope": "^3.7.0",
8589
"@types/eslint-visitor-keys": "^1.0.0",
8690
"@types/estree": "^0.0.51",
91+
"@types/less": "^3.0.3",
8792
"@types/mocha": "^9.0.0",
8893
"@types/node": "^16.0.0",
8994
"@types/postcss-safe-parser": "^5.0.1",
95+
"@types/stylus": "^0.48.38",
9096
"@typescript-eslint/eslint-plugin": "^5.4.0",
9197
"@typescript-eslint/parser": "^5.4.1-0",
9298
"@typescript-eslint/parser-v4": "npm:@typescript-eslint/parser@4",
@@ -108,6 +114,7 @@
108114
"eslint-plugin-vue": "^8.0.0",
109115
"eslint-plugin-yml": "^0.14.0",
110116
"estree-walker": "^3.0.0",
117+
"less": "^4.1.2",
111118
"locate-character": "^2.0.5",
112119
"magic-string": "^0.26.0",
113120
"markdown-it-anchor": "^8.4.1",
@@ -117,13 +124,16 @@
117124
"nyc": "^15.1.0",
118125
"pako": "^2.0.3",
119126
"pirates": "^4.0.1",
127+
"postcss-nested": "^5.0.6",
120128
"prettier": "^2.2.1",
121129
"prettier-plugin-svelte": "^2.6.0",
122130
"prism-svelte": "^0.5.0",
123131
"prismjs": "^1.25.0",
132+
"sass": "^1.51.0",
124133
"semver": "^7.3.5",
125134
"stylelint": "^14.0.0",
126135
"stylelint-config-standard": "^25.0.0",
136+
"stylus": "^0.57.0",
127137
"svelte": "^3.46.1",
128138
"svelte-adapter-ghpages": "0.0.2",
129139
"ts-node": "^10.0.0",

postcss.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"use strict"
2+
3+
// for test
4+
module.exports = {
5+
plugins: [require("postcss-nested")],
6+
}

0 commit comments

Comments
 (0)