Skip to content

Commit a9f89d8

Browse files
committed
eslint: adding javascript formatting (part 1)
1 parent 016dd3a commit a9f89d8

File tree

26 files changed

+393
-17
lines changed

26 files changed

+393
-17
lines changed

lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public class EslintFormatterStep {
4848
public static final String DEFAULT_ESLINT_VERSION = "8.28.0";
4949

5050
public enum PopularStyleGuide {
51-
STANDARD_WITH_TYPESCRIPT("standard-with-typescript") {
51+
TS_STANDARD_WITH_TYPESCRIPT("standard-with-typescript") {
5252
@Override
5353
public Map<String, String> devDependencies() {
5454
Map<String, String> dependencies = new LinkedHashMap<>();
@@ -60,7 +60,7 @@ public Map<String, String> devDependencies() {
6060
return dependencies;
6161
}
6262
},
63-
XO_TYPESCRIPT("xo-typescript") {
63+
TS_XO_TYPESCRIPT("xo-typescript") {
6464
@Override
6565
public Map<String, String> devDependencies() {
6666
Map<String, String> dependencies = new LinkedHashMap<>();
@@ -69,6 +69,42 @@ public Map<String, String> devDependencies() {
6969
dependencies.put("typescript", "4.9.3");
7070
return dependencies;
7171
}
72+
},
73+
JS_AIRBNB("airbnb") {
74+
@Override
75+
public Map<String, String> devDependencies() {
76+
Map<String, String> dependencies = new LinkedHashMap<>();
77+
dependencies.put("eslint-config-airbnb-base", "15.0.0");
78+
dependencies.put("eslint-plugin-import", "2.26.0");
79+
return dependencies;
80+
}
81+
},
82+
JS_GOOGLE("google") {
83+
@Override
84+
public Map<String, String> devDependencies() {
85+
Map<String, String> dependencies = new LinkedHashMap<>();
86+
dependencies.put("eslint-config-google", "0.14.0");
87+
return dependencies;
88+
}
89+
},
90+
JS_STANDARD("standard") {
91+
@Override
92+
public Map<String, String> devDependencies() {
93+
Map<String, String> dependencies = new LinkedHashMap<>();
94+
dependencies.put("eslint-config-standard", "17.0.0");
95+
dependencies.put("eslint-plugin-import", "2.26.0");
96+
dependencies.put("eslint-plugin-n", "15.6.0");
97+
dependencies.put("eslint-plugin-promise", "6.1.1");
98+
return dependencies;
99+
}
100+
},
101+
JS_XO("xo") {
102+
@Override
103+
public Map<String, String> devDependencies() {
104+
Map<String, String> dependencies = new LinkedHashMap<>();
105+
dependencies.put("eslint-config-xo", "0.43.1");
106+
return dependencies;
107+
}
72108
};
73109

74110
private final String popularStyleGuideName;

plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ void useEslint() throws IOException {
163163

164164
@Test
165165
void useXoStandardRules() throws IOException {
166-
setFile(".eslintrc.js").toResource("npm/eslint/typescript/standard_rules_xo/.eslintrc.js");
167-
setFile("tsconfig.json").toResource("npm/eslint/typescript/standard_rules_xo/tsconfig.json");
166+
setFile(".eslintrc.js").toResource("npm/eslint/typescript/styleguide/xo/.eslintrc.js");
167+
setFile("tsconfig.json").toResource("npm/eslint/typescript/styleguide/xo/tsconfig.json");
168168
setFile("build.gradle").toLines(
169169
"plugins {",
170170
" id 'com.diffplug.spotless'",
@@ -176,15 +176,15 @@ void useXoStandardRules() throws IOException {
176176
" eslint().styleGuide('xo-typescript').configFile('.eslintrc.js')",
177177
" }",
178178
"}");
179-
setFile("test.ts").toResource("npm/eslint/typescript/standard_rules_xo/typescript.dirty");
179+
setFile("test.ts").toResource("npm/eslint/typescript/styleguide/xo/typescript.dirty");
180180
gradleRunner().withArguments("--stacktrace", "spotlessApply").build();
181-
assertFile("test.ts").sameAsResource("npm/eslint/typescript/standard_rules_xo/typescript.clean");
181+
assertFile("test.ts").sameAsResource("npm/eslint/typescript/styleguide/xo/typescript.clean");
182182
}
183183

184184
@Test
185185
void useStandardWithTypescriptRules() throws IOException {
186-
setFile(".eslintrc.js").toResource("npm/eslint/typescript/standard_rules_standard_with_typescript/.eslintrc.js");
187-
setFile("tsconfig.json").toResource("npm/eslint/typescript/standard_rules_standard_with_typescript/tsconfig.json");
186+
setFile(".eslintrc.js").toResource("npm/eslint/typescript/styleguide/standard_with_typescript/.eslintrc.js");
187+
setFile("tsconfig.json").toResource("npm/eslint/typescript/styleguide/standard_with_typescript/tsconfig.json");
188188
setFile("build.gradle").toLines(
189189
"plugins {",
190190
" id 'com.diffplug.spotless'",
@@ -196,8 +196,8 @@ void useStandardWithTypescriptRules() throws IOException {
196196
" eslint().styleGuide('standard-with-typescript').configFile('.eslintrc.js')",
197197
" }",
198198
"}");
199-
setFile("test.ts").toResource("npm/eslint/typescript/standard_rules_standard_with_typescript/typescript.dirty");
199+
setFile("test.ts").toResource("npm/eslint/typescript/styleguide/standard_with_typescript/typescript.dirty");
200200
gradleRunner().withArguments("--stacktrace", "spotlessApply").build();
201-
assertFile("test.ts").sameAsResource("npm/eslint/typescript/standard_rules_standard_with_typescript/typescript.clean");
201+
assertFile("test.ts").sameAsResource("npm/eslint/typescript/styleguide/standard_with_typescript/typescript.clean");
202202
}
203203
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
module.exports = {
2+
"env": {
3+
"browser": true,
4+
"es2021": true
5+
},
6+
"extends": "eslint:recommended",
7+
"overrides": [
8+
],
9+
"parserOptions": {
10+
"ecmaVersion": "latest",
11+
"sourceType": "module"
12+
},
13+
"rules": {
14+
"indent": [
15+
"error",
16+
2
17+
],
18+
"linebreak-style": [
19+
"error",
20+
"unix"
21+
],
22+
"quotes": [
23+
"error",
24+
"double"
25+
],
26+
"semi": [
27+
"error",
28+
"always"
29+
]
30+
}
31+
};
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
var numbers=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
2+
];
3+
4+
const p = {
5+
first: "Peter",
6+
last : "Pan",
7+
get fullName() { return this.first + " " + this.last; }
8+
};
9+
10+
const str = "Hello, world!"
11+
;
12+
13+
var str2=str.charAt(3)+str[0];
14+
15+
var multilinestr = "Hello \
16+
World"
17+
;
18+
19+
function test (a, b = "world") { let combined =a+ b; return combined;}
20+
21+
test ("Hello");
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
var numbers=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
2+
];
3+
4+
const p = {
5+
first: 'Peter',
6+
last : 'Pan',
7+
get fullName() { return this.first + ' ' + this.last; }
8+
};
9+
10+
const str = 'Hello, world!'
11+
;
12+
13+
var str2=str.charAt(3)+str[0];
14+
15+
var multilinestr = 'Hello \
16+
World'
17+
;
18+
19+
function test (a, b = 'world') { let combined =a+ b; return combined};
20+
21+
test ('Hello');
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module.exports = {
2+
env: {
3+
browser: true,
4+
es2021: true,
5+
},
6+
extends: 'airbnb-base',
7+
overrides: [
8+
],
9+
parserOptions: {
10+
ecmaVersion: 'latest',
11+
sourceType: 'module',
12+
},
13+
rules: {
14+
},
15+
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
2+
];
3+
4+
const p = {
5+
first: 'Peter',
6+
last: 'Pan',
7+
get fullName() { return `${this.first} ${this.last}`; },
8+
};
9+
10+
const str = 'Hello, world!';
11+
const str2 = str.charAt(3) + str[0];
12+
13+
const multilinestr = 'Hello \
14+
World';
15+
function test(a, b = 'world') { const combined = a + b; return combined; }
16+
17+
test('Hello');
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
var numbers=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
2+
];
3+
4+
const p = {
5+
first: "Peter",
6+
last : "Pan",
7+
get fullName() { return this.first + " " + this.last; }
8+
};
9+
10+
const str = "Hello, world!"
11+
;
12+
13+
var str2=str.charAt(3)+str[0];
14+
15+
var multilinestr = "Hello \
16+
World"
17+
;
18+
19+
function test (a, b = "world") { let combined =a+ b; return combined};
20+
21+
test ("Hello");
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module.exports = {
2+
'env': {
3+
'browser': true,
4+
'es2021': true,
5+
},
6+
'extends': 'google',
7+
'overrides': [
8+
],
9+
'parserOptions': {
10+
'ecmaVersion': 'latest',
11+
'sourceType': 'module',
12+
},
13+
'rules': {
14+
},
15+
};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const numbers=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
2+
];
3+
4+
const p = {
5+
first: 'Peter',
6+
last: 'Pan',
7+
get fullName() {
8+
return this.first + ' ' + this.last;
9+
},
10+
};
11+
12+
const str = 'Hello, world!'
13+
;
14+
15+
const str2=str.charAt(3)+str[0];
16+
17+
const multilinestr = 'Hello \
18+
World'
19+
;
20+
21+
function test(a, b = 'world') {
22+
const combined =a+ b; return combined;
23+
};
24+
25+
test('Hello');

0 commit comments

Comments
 (0)