kensington-eslint-plugin 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -470,7 +470,7 @@ Auto-fixable when the group's members are contiguous in the source. Non-contiguo
|
|
|
470
470
|
|
|
471
471
|
### `prefer-array-for-multiline-content`
|
|
472
472
|
|
|
473
|
-
Mirrors what `html-to-kensington` emits: when a tag's content
|
|
473
|
+
Mirrors what `html-to-kensington` emits: when a tag's content occupies its own line(s) — separated from both the opening and closing paren — it goes in an array, even when it's the only item. The array form makes line-by-line edits easier (no need to add `[ ]` when adding a sibling).
|
|
474
474
|
|
|
475
475
|
```js
|
|
476
476
|
// Bad
|
|
@@ -482,6 +482,12 @@ t.div({ class: 'x' },
|
|
|
482
482
|
t.div({ class: 'x' }, [
|
|
483
483
|
t.p('only'),
|
|
484
484
|
]);
|
|
485
|
+
|
|
486
|
+
// Also good — content trails on the closing-paren line, no array needed
|
|
487
|
+
t.a({
|
|
488
|
+
href: 'https://example.com',
|
|
489
|
+
target: '_blank',
|
|
490
|
+
}, 'VS Code');
|
|
485
491
|
```
|
|
486
492
|
|
|
487
493
|
Auto-fixable. Single-line calls (`t.div({…}, t.p('inner'))`) are left alone.
|
package/package.json
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
// Tag content
|
|
2
|
-
//
|
|
3
|
-
//
|
|
1
|
+
// Tag content that occupies its own line(s) — separated from both the call's
|
|
2
|
+
// opening paren and its closing paren — must be wrapped in an array, even when
|
|
3
|
+
// it's the only item. Mirrors what html-to-kensington emits when a tag's
|
|
4
|
+
// content can't fit on a single line. Content that trails on the closing-paren
|
|
5
|
+
// line stays bare.
|
|
4
6
|
|
|
5
7
|
import { isTagCall, getObjectNames, objectNamesSchema } from './_utils.js';
|
|
6
8
|
|
|
@@ -48,15 +50,18 @@ export default {
|
|
|
48
50
|
if (content.type === 'SpreadElement') { return; }
|
|
49
51
|
|
|
50
52
|
// The "opening line" is where the open paren sits — same line as the
|
|
51
|
-
// callee's last token. Content
|
|
53
|
+
// callee's last token. Content that touches either the opening-paren
|
|
54
|
+
// line or the closing-paren line stays bare.
|
|
52
55
|
const openParenLine = node.callee.loc.end.line;
|
|
53
56
|
if (content.loc.start.line <= openParenLine) { return; }
|
|
54
57
|
|
|
58
|
+
const closeParen = sourceCode.getLastToken(node);
|
|
59
|
+
if (closeParen && closeParen.value === ')' && content.loc.end.line >= closeParen.loc.start.line) { return; }
|
|
60
|
+
|
|
55
61
|
context.report({
|
|
56
62
|
node: content,
|
|
57
63
|
messageId: 'wrapInArray',
|
|
58
64
|
*fix(fixer) {
|
|
59
|
-
const closeParen = sourceCode.getLastToken(node);
|
|
60
65
|
const tokenAfterContent = sourceCode.getTokenAfter(content);
|
|
61
66
|
const hasTrailingComma = tokenAfterContent
|
|
62
67
|
&& tokenAfterContent.value === ','
|