-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(eslint-config-angular): support line statements (#155)
- Loading branch information
Showing
10 changed files
with
281 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,5 +28,6 @@ module.exports = { | |
* @note: [*.js, *.ts] | ||
*/ | ||
'no-param-reassign': 'off', | ||
'no-case-declarations': 'error', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
packages/eslint-config-angular/internal/line-statements.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
module.exports = { | ||
overrides: [ | ||
{ | ||
files: ['*.ts'], | ||
plugins: ['@typescript-eslint'], | ||
rules: { | ||
'lines-around-comment': [ | ||
'error', | ||
{ | ||
beforeBlockComment: false, | ||
afterBlockComment: false, | ||
beforeLineComment: false, | ||
afterLineComment: false, | ||
allowBlockStart: true, | ||
allowBlockEnd: true, | ||
allowObjectStart: true, | ||
allowObjectEnd: true, | ||
allowArrayStart: true, | ||
allowArrayEnd: true, | ||
allowClassStart: true, | ||
allowClassEnd: true, | ||
applyDefaultIgnorePatterns: true, | ||
}, | ||
], | ||
'lines-between-class-members': 'off', | ||
'@typescript-eslint/lines-between-class-members': [ | ||
'error', | ||
'always', | ||
{ exceptAfterSingleLine: true, exceptAfterOverload: true }, | ||
], | ||
'padding-line-between-statements': 'off', | ||
'@typescript-eslint/padding-line-between-statements': [ | ||
'error', | ||
{ blankLine: 'always', prev: '*', next: 'block' }, | ||
{ blankLine: 'always', prev: 'block', next: '*' }, | ||
{ blankLine: 'always', prev: '*', next: 'block-like' }, | ||
{ blankLine: 'always', prev: 'block-like', next: '*' }, | ||
{ blankLine: 'always', prev: '*', next: 'return' }, | ||
{ blankLine: 'always', prev: 'directive', next: '*' }, | ||
{ blankLine: 'always', prev: '*', next: ['interface', 'type'] }, | ||
{ blankLine: 'always', prev: ['const', 'let', 'var'], next: '*' }, | ||
{ | ||
blankLine: 'any', | ||
prev: ['const', 'let', 'var', 'export'], | ||
next: ['const', 'let', 'var', 'export'], | ||
}, | ||
{ blankLine: 'any', prev: '*', next: ['case', 'default'] }, | ||
{ blankLine: 'any', prev: ['case', 'default'], next: '*' }, | ||
{ blankLine: 'any', prev: '*', next: 'class' }, | ||
{ blankLine: 'any', prev: 'class', next: '*' }, | ||
{ blankLine: 'any', prev: 'directive', next: 'directive' }, | ||
], | ||
}, | ||
}, | ||
], | ||
}; |
53 changes: 53 additions & 0 deletions
53
.../eslint-config-angular/test/line-statements/__fixtures__/line-statements-happy.fixture.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
class A1 {} | ||
class B1 {} | ||
|
||
function a1() {} | ||
|
||
function b1() {} | ||
|
||
function c1() { | ||
const value = '123'; | ||
|
||
return value + 'etc'; | ||
} | ||
|
||
const d1: string | null = null; | ||
let e1: string | null = null; | ||
|
||
switch (d1) { | ||
case '1': { | ||
e1 = '1'; | ||
break; | ||
} | ||
case '2': { | ||
e1 = '2'; | ||
break; | ||
} | ||
default: { | ||
e1 = d1; | ||
break; | ||
} | ||
} | ||
|
||
let sum = 0; | ||
|
||
for (let i = 0; i < 5; i++) { | ||
sum += i; | ||
} | ||
|
||
sum = 0; | ||
|
||
class LinesBetween { | ||
x; | ||
y; | ||
|
||
foo(x?: string); | ||
foo(x?: string, y?: string); | ||
foo() { | ||
//... | ||
} | ||
|
||
bar() { | ||
//... | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...slint-config-angular/test/line-statements/__fixtures__/line-statements-unhappy.fixture.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
class A2 {} | ||
class B2 {} | ||
|
||
function a2() {} | ||
function b2() {} | ||
function c2() { | ||
const value = '123'; | ||
return value + 'etc'; | ||
} | ||
|
||
const d2: string | null = null; | ||
let e2: string | null = null; | ||
switch (d2) { | ||
case '1': { | ||
e1 = '1'; | ||
break; | ||
} | ||
|
||
case '2': { | ||
e1 = '2'; | ||
break; | ||
} | ||
|
||
default: { | ||
e1 = d1; | ||
break; | ||
} | ||
} | ||
|
||
let sum2: number = 0; | ||
for (let i = 0; i < 5; i++) { | ||
sum2 += i; | ||
} | ||
sum2 = 0; | ||
|
||
class LinesBetween2 { | ||
x; | ||
y; | ||
foo(x?: string); | ||
foo(x?: string, y?: string); | ||
foo() { | ||
//... | ||
} | ||
bar() { | ||
//... | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...lint-config-angular/test/line-statements/__snapshots__/line-statements-happy.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`imports / happy path happy 1`] = `""`; |
76 changes: 76 additions & 0 deletions
76
...nt-config-angular/test/line-statements/__snapshots__/line-statements-unhappy.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`line statements / unhappy path unhappy 1`] = ` | ||
"error: Expected blank line before this statement (@typescript-eslint/padding-line-between-statements) at packages/eslint-config-angular/test/line-statements/__fixtures__/line-statements-unhappy.fixture.ts:5:1: | ||
3 | | ||
4 | function a2() {} | ||
> 5 | function b2() {} | ||
| ^ | ||
6 | function c2() { | ||
7 | const value = '123'; | ||
8 | return value + 'etc'; | ||
error: Expected blank line before this statement (@typescript-eslint/padding-line-between-statements) at packages/eslint-config-angular/test/line-statements/__fixtures__/line-statements-unhappy.fixture.ts:6:1: | ||
4 | function a2() {} | ||
5 | function b2() {} | ||
> 6 | function c2() { | ||
| ^ | ||
7 | const value = '123'; | ||
8 | return value + 'etc'; | ||
9 | } | ||
error: Expected blank line before this statement (@typescript-eslint/padding-line-between-statements) at packages/eslint-config-angular/test/line-statements/__fixtures__/line-statements-unhappy.fixture.ts:8:5: | ||
6 | function c2() { | ||
7 | const value = '123'; | ||
> 8 | return value + 'etc'; | ||
| ^ | ||
9 | } | ||
10 | | ||
11 | const d2: string | null = null; | ||
error: Expected blank line before this statement (@typescript-eslint/padding-line-between-statements) at packages/eslint-config-angular/test/line-statements/__fixtures__/line-statements-unhappy.fixture.ts:13:1: | ||
11 | const d2: string | null = null; | ||
12 | let e2: string | null = null; | ||
> 13 | switch (d2) { | ||
| ^ | ||
14 | case '1': { | ||
15 | e1 = '1'; | ||
16 | break; | ||
error: Expected blank line before this statement (@typescript-eslint/padding-line-between-statements) at packages/eslint-config-angular/test/line-statements/__fixtures__/line-statements-unhappy.fixture.ts:31:1: | ||
29 | | ||
30 | let sum2: number = 0; | ||
> 31 | for (let i = 0; i < 5; i++) { | ||
| ^ | ||
32 | sum2 += i; | ||
33 | } | ||
34 | sum2 = 0; | ||
error: Expected blank line before this statement (@typescript-eslint/padding-line-between-statements) at packages/eslint-config-angular/test/line-statements/__fixtures__/line-statements-unhappy.fixture.ts:34:1: | ||
32 | sum2 += i; | ||
33 | } | ||
> 34 | sum2 = 0; | ||
| ^ | ||
35 | | ||
36 | class LinesBetween2 { | ||
37 | x; | ||
error: Expected blank line between class members (@typescript-eslint/lines-between-class-members) at packages/eslint-config-angular/test/line-statements/__fixtures__/line-statements-unhappy.fixture.ts:44:5: | ||
42 | //... | ||
43 | } | ||
> 44 | bar() { | ||
| ^ | ||
45 | //... | ||
46 | } | ||
47 | } | ||
7 errors found. | ||
7 errors potentially fixable with the \`--fix\` option." | ||
`; |
21 changes: 21 additions & 0 deletions
21
packages/eslint-config-angular/test/line-statements/line-statements-happy.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import ESlint from 'eslint'; | ||
import path from 'path'; | ||
|
||
describe('imports / happy path', () => { | ||
const cli = new ESlint.CLIEngine({ | ||
cwd: path.join(__dirname, '..'), | ||
useEslintrc: false, | ||
baseConfig: { | ||
extends: ['../internal/base', '../internal/line-statements'], | ||
}, | ||
}); | ||
|
||
it('happy', () => { | ||
const codeframe = cli.getFormatter('codeframe'); | ||
const report = cli.executeOnFiles([ | ||
path.join(__dirname, './__fixtures__/line-statements-happy.fixture.ts'), | ||
]); | ||
|
||
expect(codeframe(report.results)).toMatchSnapshot(); | ||
}); | ||
}); |
21 changes: 21 additions & 0 deletions
21
packages/eslint-config-angular/test/line-statements/line-statements-unhappy.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import ESlint from 'eslint'; | ||
import path from 'path'; | ||
|
||
describe('line statements / unhappy path', () => { | ||
const cli = new ESlint.CLIEngine({ | ||
cwd: path.join(__dirname, '..'), | ||
useEslintrc: false, | ||
baseConfig: { | ||
extends: ['../internal/base', '../internal/line-statements'], | ||
}, | ||
}); | ||
|
||
it('unhappy', () => { | ||
const codeframe = cli.getFormatter('codeframe'); | ||
const report = cli.executeOnFiles([ | ||
path.join(__dirname, './__fixtures__/line-statements-unhappy.fixture.ts'), | ||
]); | ||
|
||
expect(codeframe(report.results)).toMatchSnapshot(); | ||
}); | ||
}); |