Skip to content

Commit

Permalink
Fix wrong auto-fix in yml/block-mapping rule
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi committed Jan 7, 2021
1 parent d4469c1 commit f3bc84d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/rules/block-mapping.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { AST } from "yaml-eslint-parser"
import type { YAMLNodeOrToken, RuleFixer, Fix, RuleContext } from "../types"
import { createRule } from "../utils"
import { isComma } from "../utils/ast-utils"
import { isColon, isComma } from "../utils/ast-utils"
import {
calcExpectIndentForPairs,
hasTabIndent,
Expand Down Expand Up @@ -333,6 +333,15 @@ function buildFixFlowToBlock(node: AST.YAMLFlowMapping, context: RuleContext) {
[prevToken.range[1], pair.range[0]],
`\n${expectIndent}`,
)
const colonToken = sourceCode.getTokenAfter(pair.key!, isColon)!
if (
colonToken.range[1] ===
sourceCode.getTokenAfter(colonToken, {
includeComments: true,
})!.range[0]
) {
yield fixer.insertTextAfter(colonToken, " ")
}
yield* processIndentFix(fixer, expectIndent, pair.value!, context)
prev = pair
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"message": "Must use block style mappings.",
"line": 2,
"column": 1
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# {}
{
"a":"a","b":"b"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# block-mapping/invalid/flow-colon01-input.yml
"a": "a"
"b": "b"

0 comments on commit f3bc84d

Please sign in to comment.