Skip to content

Commit

Permalink
fix: include indentation when counting line width
Browse files Browse the repository at this point in the history
  • Loading branch information
NullVoxPopuli committed Mar 22, 2021
1 parent 8559f1e commit b86643a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
8 changes: 6 additions & 2 deletions lib/rules/decorator-position.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 7 additions & 2 deletions tests/lib/rules/decorator-position-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }],
Expand Down Expand Up @@ -154,6 +158,7 @@ ruleTester.run('JS: decorator-position', rule, {
{
code: stripIndent`
class Foo {
// one character over inline max printWidth
@foo('bizbangbarbazboo')
fizz;
}
Expand Down

0 comments on commit b86643a

Please sign in to comment.