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): add decorator position package (#217)
* feat(eslint-config-angular): add decorator position package * ci: remove 10.x, 12.x node versions & add 18.x node version
- Loading branch information
Daniil Dubrava
committed
Nov 10, 2022
1 parent
c5bb8b3
commit d3b9d1f
Showing
10 changed files
with
130 additions
and
2 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
19 changes: 19 additions & 0 deletions
19
packages/eslint-config-angular/decorator-position/index.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,19 @@ | ||
module.exports = { | ||
overrides: [ | ||
{ | ||
files: ['*.ts'], | ||
parser: '@typescript-eslint/parser', | ||
plugins: ['@typescript-eslint', 'decorator-position'], | ||
rules: { | ||
'decorator-position/decorator-position': [ | ||
'error', | ||
{ | ||
printWidth: 120, | ||
properties: 'above', | ||
methods: 'above', | ||
}, | ||
], | ||
}, | ||
}, | ||
], | ||
}; |
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
15 changes: 15 additions & 0 deletions
15
...t-config-angular/test/decorator-position/__fixtures__/decorator-position-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,15 @@ | ||
function Output() { | ||
return function (target: any, propertyKey: string) {}; | ||
} | ||
|
||
function enumerable() { | ||
return function (target: any, propertyKey: string) {}; | ||
} | ||
|
||
class A { | ||
@Output() | ||
name: any; | ||
|
||
@enumerable() | ||
foo() {} | ||
} |
13 changes: 13 additions & 0 deletions
13
...config-angular/test/decorator-position/__fixtures__/decorator-position-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,13 @@ | ||
function Input() { | ||
return function (target: any, propertyKey: string) {}; | ||
} | ||
|
||
function pure() { | ||
return function (target: any, propertyKey: string) {}; | ||
} | ||
|
||
class B { | ||
@Input() name: any; | ||
|
||
@pure() foo() {} | ||
} |
3 changes: 3 additions & 0 deletions
3
...onfig-angular/test/decorator-position/__snapshots__/decorator-position-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[`decorator-position / happy path happy 1`] = `""`; |
25 changes: 25 additions & 0 deletions
25
...fig-angular/test/decorator-position/__snapshots__/decorator-position-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,25 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`decorator-position / unhappy path unhappy 1`] = ` | ||
"error: Expected @Input to be on the line above (decorator-position/decorator-position) at packages/eslint-config-angular/test/decorator-position/__fixtures__/decorator-position-unhappy.fixture.ts:10:3: | ||
8 | | ||
9 | class B { | ||
> 10 | @Input() name: any; | ||
| ^ | ||
11 | | ||
12 | @pure() foo() {} | ||
13 | } | ||
error: Expected @pure to be on the line above (decorator-position/decorator-position) at packages/eslint-config-angular/test/decorator-position/__fixtures__/decorator-position-unhappy.fixture.ts:12:3: | ||
10 | @Input() name: any; | ||
11 | | ||
> 12 | @pure() foo() {} | ||
| ^ | ||
13 | } | ||
14 | | ||
2 errors found. | ||
2 errors potentially fixable with the \`--fix\` option." | ||
`; |
25 changes: 25 additions & 0 deletions
25
packages/eslint-config-angular/test/decorator-position/decorator-position-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,25 @@ | ||
import ESlint from 'eslint'; | ||
import path from 'path'; | ||
|
||
describe('decorator-position / happy path', () => { | ||
const cli = new ESlint.CLIEngine({ | ||
cwd: path.join(__dirname, '..'), | ||
useEslintrc: false, | ||
baseConfig: { | ||
extends: ['../decorator-position'], | ||
}, | ||
}); | ||
|
||
it('happy', () => { | ||
const codeframe = cli.getFormatter('codeframe'); | ||
|
||
const report = cli.executeOnFiles([ | ||
path.join( | ||
__dirname, | ||
'./__fixtures__/decorator-position-happy.fixture.ts' | ||
), | ||
]); | ||
|
||
expect(codeframe(report.results)).toMatchSnapshot(); | ||
}); | ||
}); |
25 changes: 25 additions & 0 deletions
25
packages/eslint-config-angular/test/decorator-position/decorator-position-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,25 @@ | ||
import ESlint from 'eslint'; | ||
import path from 'path'; | ||
|
||
describe('decorator-position / unhappy path', () => { | ||
const cli = new ESlint.CLIEngine({ | ||
cwd: path.join(__dirname, '..'), | ||
useEslintrc: false, | ||
baseConfig: { | ||
extends: ['../decorator-position'], | ||
}, | ||
}); | ||
|
||
it('unhappy', () => { | ||
const codeframe = cli.getFormatter('codeframe'); | ||
|
||
const report = cli.executeOnFiles([ | ||
path.join( | ||
__dirname, | ||
'./__fixtures__/decorator-position-unhappy.fixture.ts' | ||
), | ||
]); | ||
|
||
expect(codeframe(report.results)).toMatchSnapshot(); | ||
}); | ||
}); |