Skip to content

Commit 37d1c4f

Browse files
Merge pull request #61 from Typeform/WEB-4636/add-curly-and-prefer-destructuring
2 parents 61ff8f9 + 65014cc commit 37d1c4f

File tree

5 files changed

+40
-0
lines changed

5 files changed

+40
-0
lines changed

index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ module.exports = {
2323
},
2424
rules: {
2525
'no-var': 'warn',
26+
'curly': 'warn',
27+
'prefer-destructuring': 'warn',
2628
'@typescript-eslint/no-extra-semi': 'off',
2729
'import/order': [
2830
'warn',

index.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,28 @@ describe('eslint config', () => {
3636
expect(output.includes('"errorCount":0')).toBeTruthy()
3737
expect(output.includes('"warningCount":1')).toBeTruthy()
3838
})
39+
40+
it('should warn if braces are not used', () => {
41+
const output = child_process
42+
.execSync('yarn eslint -f "json" --no-ignore test-cases/warn-curly.js')
43+
.toString()
44+
45+
expect(output.includes('"ruleId":"curly"')).toBeTruthy()
46+
expect(output.includes('"errorCount":0')).toBeTruthy()
47+
expect(output.includes('"warningCount":2')).toBeTruthy()
48+
})
49+
50+
it('should warn if destructuring is not used', () => {
51+
const output = child_process
52+
.execSync(
53+
'yarn eslint -f "json" --no-ignore test-cases/warn-prefer-destructuring.js'
54+
)
55+
.toString()
56+
57+
expect(output.includes('"ruleId":"prefer-destructuring"')).toBeTruthy()
58+
expect(output.includes('"errorCount":0')).toBeTruthy()
59+
expect(output.includes('"warningCount":1')).toBeTruthy()
60+
})
3961
// #endregion
4062

4163
// #region Fail

test-cases/pass.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
const myConstant = 34
22
let myVariable = myConstant + 5
3+
const data = { a: 5, b: 1 }
4+
if (true) {
5+
const { a } = data
6+
myVariable += a + data.b
7+
}
38
return myVariable

test-cases/warn-curly.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
let condition1 = true
2+
let condition2 = false
3+
let myVariable = 34
4+
if (condition1) myVariable += 5
5+
if (condition2)
6+
myVariable = myVariable * myVariable + 5 - myVariable - 2 * myVariable
7+
return myVariable
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
const data = { a: 5, b: 1 }
2+
const a = data.a
3+
const myVariable = 34 + a + data.b
4+
return myVariable

0 commit comments

Comments
 (0)