Skip to content

Commit

Permalink
feat(eslint-config-angular): add decorator position package (#217)
Browse files Browse the repository at this point in the history
* 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
Show file tree
Hide file tree
Showing 10 changed files with 130 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check.yml
Expand Up @@ -11,7 +11,7 @@ jobs:

strategy:
matrix:
node-version: [10.x, 12.x, 14.x, 16.x]
node-version: [14.x, 16.x, 18.x]

steps:
- uses: actions/checkout@v2
Expand Down
1 change: 1 addition & 0 deletions packages/eslint-config-angular/README.md
Expand Up @@ -36,6 +36,7 @@ You can also include `optional` configurations, however, you are responsible for
'@tinkoff/eslint-config-angular/file-progress',
'@tinkoff/eslint-config-angular/line-statements',
'@tinkoff/eslint-config-angular/member-ordering',
'@tinkoff/eslint-config-angular/decorator-position',
],
}
```
Expand Down
19 changes: 19 additions & 0 deletions packages/eslint-config-angular/decorator-position/index.js
@@ -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',
},
],
},
},
],
};
4 changes: 3 additions & 1 deletion packages/eslint-config-angular/package.json
Expand Up @@ -15,6 +15,7 @@
"member-ordering",
"promise",
"file-progress",
"decorator-position",
"recommended",
"rxjs",
"index.js",
Expand All @@ -35,7 +36,8 @@
"eslint-plugin-html": "^6.2.0",
"eslint-plugin-rxjs": "^5.0.2",
"eslint-plugin-rxjs-angular": "^2.0.0",
"eslint-plugin-simple-import-sort": "^7.0.0"
"eslint-plugin-simple-import-sort": "^7.0.0",
"eslint-plugin-decorator-position": "^5.0.1"
},
"peerDependencies": {
"@tinkoff/eslint-config": "^1.31.1",
Expand Down
@@ -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() {}
}
@@ -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() {}
}
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`decorator-position / happy path happy 1`] = `""`;
@@ -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."
`;
@@ -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();
});
});
@@ -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();
});
});

0 comments on commit d3b9d1f

Please sign in to comment.