diff --git a/lib/rules/decorator-position.js b/lib/rules/decorator-position.js index 634d1f00..0576bc7f 100644 --- a/lib/rules/decorator-position.js +++ b/lib/rules/decorator-position.js @@ -140,7 +140,7 @@ function decoratorPositionRule(context) { const userOptions = context.options[0] || {}; const filePath = context.getFilename(); const { printWidth } = lineLength(userOptions, filePath); - const options = normalizeOptions({ ...userOptions, printWidth: printWidth + 1 }); + const options = normalizeOptions({ ...userOptions, printWidth }); return { 'ClassProperty[decorators.length=1]:exit'(node) { @@ -382,7 +382,11 @@ function lengthAsInline(context, node) { // - property name // - type annotation (and !) // - etc - return context.getSourceCode().getText(node).replace(/\s+/, ' ').length; + return ( + context.getSourceCode().getText(node).replace(/\s+/, ' ').length + + // this is the only way to get indentation? + node.loc.start.column + ); } function decoratorInfo(context, node, decoratorConfig, options) { diff --git a/package.json b/package.json index a7bf865c..e3c3c400 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "test": "jest", "test:debug": "node --inspect node_modules/.bin/jest --runInBand", "test:debug-watch": "node --inspect node_modules/.bin/jest --watch --runInBand", + "test:debug:named": "node --inspect node_modules/.bin/jest --runInBand --watch --testNamePattern", "test:coverage": "jest --coverage", "test:watch": "jest --watchAll", "update": "node ./scripts/update-rules.js", diff --git a/tests/lib/rules/decorator-position-js.js b/tests/lib/rules/decorator-position-js.js index 729a806f..fc88afea 100644 --- a/tests/lib/rules/decorator-position-js.js +++ b/tests/lib/rules/decorator-position-js.js @@ -116,9 +116,13 @@ ruleTester.run('JS: decorator-position', rule, { { code: stripIndent` class Foo { - @foo('bizbangbarbazboo') fizz; + // 32 characters + @foo('bizbangbarbazboo') + fizz; - @action('bidgbarbazboo') fizz; + // 32 characters + @action('bidgbarbazboo') + fizz; } `, options: [{ printWidth: 30 }], @@ -154,6 +158,7 @@ ruleTester.run('JS: decorator-position', rule, { { code: stripIndent` class Foo { + // one character over inline max printWidth @foo('bizbangbarbazboo') fizz; }