From c5bf6beee35f3ce98ed6d43573224d9a4272f282 Mon Sep 17 00:00:00 2001 From: NullVoxPopuli Date: Tue, 24 Mar 2020 06:25:31 -0400 Subject: [PATCH] fix: multi-line decorators now behave appropriately --- .github/workflows/lint.yml | 3 +++ lib/rules/decorator-position.js | 2 +- tests/lib/rules/decorator-position.js | 29 +++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index c2fdfb37..ee96b7ed 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -51,6 +51,9 @@ jobs: - uses: volta-cli/action@v1 - uses: wagoid/commitlint-github-action@v1 + env: + GITHUB_TOKEN: ${{ secrets.GH_PAT }} + # - run: yarn && volta install @commitlint/cli # - run: | # git log --pretty=format:%B master...$GITHUB_REF diff --git a/lib/rules/decorator-position.js b/lib/rules/decorator-position.js index 176a1671..b4c4eebc 100644 --- a/lib/rules/decorator-position.js +++ b/lib/rules/decorator-position.js @@ -183,7 +183,7 @@ function normalizeConfig(config, intent) { // /////////////////////////////////// function linePositioning(decorator, key) { - const decoratorLine = decorator.expression.loc.start.line; + const decoratorLine = decorator.expression.loc.end.line; const keyLine = key.loc.start.line; const onDifferentLines = decoratorLine !== keyLine; const onSameLine = decoratorLine === keyLine; diff --git a/tests/lib/rules/decorator-position.js b/tests/lib/rules/decorator-position.js index f10338fd..ade73dc6 100644 --- a/tests/lib/rules/decorator-position.js +++ b/tests/lib/rules/decorator-position.js @@ -79,6 +79,16 @@ ruleTester.run('JS: decorator-position', rule, { }, ], }, + { + code: stripIndent` + class Foo { + @foo({ + bigDecorator: true, + }) foo; + } + `, + options: [{ onSameLine: ['@foo'] }], + }, ], invalid: [ { @@ -139,6 +149,25 @@ ruleTester.run('JS: decorator-position', rule, { } `, }, + { + code: stripIndent` + class Foo { + @foo({ + bigDecorator: true, + }) foo; + } + `, + options: [{ onDifferentLines: ['@foo'] }], + errors: [{ message: 'Expected @foo to be on the line above.' }], + output: stripIndent` + class Foo { + @foo({ + bigDecorator: true, + }) + foo; + } + `, + }, ], });