eslint-plugin-yml
Advanced tools
Comparing version 1.1.0 to 1.2.0
declare const _default: { | ||
extends: string[]; | ||
rules: { | ||
"yml/block-mapping-colon-indicator-newline": string; | ||
"yml/block-mapping-question-indicator-newline": string; | ||
@@ -5,0 +6,0 @@ "yml/block-sequence-hyphen-indicator-newline": string; |
@@ -11,2 +11,3 @@ "use strict"; | ||
rules: { | ||
"yml/block-mapping-colon-indicator-newline": "off", | ||
"yml/block-mapping-question-indicator-newline": "off", | ||
@@ -13,0 +14,0 @@ "yml/block-sequence-hyphen-indicator-newline": "off", |
@@ -55,2 +55,3 @@ import type { RuleModule } from "./types"; | ||
rules: { | ||
"yml/block-mapping-colon-indicator-newline": string; | ||
"yml/block-mapping-question-indicator-newline": string; | ||
@@ -57,0 +58,0 @@ "yml/block-sequence-hyphen-indicator-newline": string; |
@@ -52,4 +52,7 @@ "use strict"; | ||
fix(fixer) { | ||
const spaces = " ".repeat(Math.max(key.loc.start.column - | ||
question.loc.end.column, 1)); | ||
const spaceCount = key.loc.start.column - question.loc.end.column; | ||
if (spaceCount < 1 && key.loc.start.line < key.loc.end.line) { | ||
return null; | ||
} | ||
const spaces = " ".repeat(Math.max(spaceCount, 1)); | ||
return fixer.replaceTextRange([question.range[1], key.range[0]], spaces); | ||
@@ -56,0 +59,0 @@ }, |
@@ -82,4 +82,3 @@ "use strict"; | ||
withinBlockStyle: (styleStack && | ||
(styleStack.withinBlockStyle || | ||
styleStack.blockStyle)) || | ||
(styleStack.withinBlockStyle || styleStack.blockStyle)) || | ||
false, | ||
@@ -124,5 +123,3 @@ }; | ||
const multiline = node.loc.start.line < node.loc.end.line; | ||
const optionType = multiline | ||
? options.multiline | ||
: options.singleline; | ||
const optionType = multiline ? options.multiline : options.singleline; | ||
if (optionType === "ignore") { | ||
@@ -138,9 +135,7 @@ return; | ||
} | ||
const canFix = canFixToBlock(mappingInfo, node) && | ||
!(0, yaml_1.hasTabIndent)(context); | ||
const canFix = canFixToBlock(mappingInfo, node) && !(0, yaml_1.hasTabIndent)(context); | ||
context.report({ | ||
loc: node.loc, | ||
messageId: "required", | ||
fix: (canFix && buildFixFlowToBlock(node, context)) || | ||
null, | ||
fix: (canFix && buildFixFlowToBlock(node, context)) || null, | ||
}); | ||
@@ -152,9 +147,7 @@ } | ||
} | ||
const canFix = canFixToFlow(mappingInfo, node) && | ||
!(0, yaml_1.hasTabIndent)(context); | ||
const canFix = canFixToFlow(mappingInfo, node) && !(0, yaml_1.hasTabIndent)(context); | ||
context.report({ | ||
loc: node.loc, | ||
messageId: "disallow", | ||
fix: (canFix && buildFixBlockToFlow(node, context)) || | ||
null, | ||
fix: (canFix && buildFixBlockToFlow(node, context)) || null, | ||
}); | ||
@@ -161,0 +154,0 @@ } |
@@ -65,4 +65,8 @@ "use strict"; | ||
fix(fixer) { | ||
const spaces = " ".repeat(Math.max(entry.loc.start.column - | ||
hyphen.loc.end.column, 1)); | ||
const spaceCount = entry.loc.start.column - hyphen.loc.end.column; | ||
if (spaceCount < 1 && | ||
entry.loc.start.line < entry.loc.end.line) { | ||
return null; | ||
} | ||
const spaces = " ".repeat(Math.max(spaceCount, 1)); | ||
return fixer.replaceTextRange([hyphen.range[1], entry.range[0]], spaces); | ||
@@ -69,0 +73,0 @@ }, |
@@ -82,4 +82,3 @@ "use strict"; | ||
withinBlockStyle: (styleStack && | ||
(styleStack.withinBlockStyle || | ||
styleStack.blockStyle)) || | ||
(styleStack.withinBlockStyle || styleStack.blockStyle)) || | ||
false, | ||
@@ -124,5 +123,3 @@ }; | ||
const multiline = node.loc.start.line < node.loc.end.line; | ||
const optionType = multiline | ||
? options.multiline | ||
: options.singleline; | ||
const optionType = multiline ? options.multiline : options.singleline; | ||
if (optionType === "ignore") { | ||
@@ -138,8 +135,8 @@ return; | ||
} | ||
const canFix = canFixToBlock(sequenceInfo, node, context.getSourceCode()) && !(0, yaml_1.hasTabIndent)(context); | ||
const canFix = canFixToBlock(sequenceInfo, node, context.getSourceCode()) && | ||
!(0, yaml_1.hasTabIndent)(context); | ||
context.report({ | ||
loc: node.loc, | ||
messageId: "required", | ||
fix: (canFix && buildFixFlowToBlock(node, context)) || | ||
null, | ||
fix: (canFix && buildFixFlowToBlock(node, context)) || null, | ||
}); | ||
@@ -151,9 +148,7 @@ } | ||
} | ||
const canFix = canFixToFlow(sequenceInfo, node, context) && | ||
!(0, yaml_1.hasTabIndent)(context); | ||
const canFix = canFixToFlow(sequenceInfo, node, context) && !(0, yaml_1.hasTabIndent)(context); | ||
context.report({ | ||
loc: node.loc, | ||
messageId: "disallow", | ||
fix: (canFix && buildFixBlockToFlow(node, context)) || | ||
null, | ||
fix: (canFix && buildFixBlockToFlow(node, context)) || null, | ||
}); | ||
@@ -160,0 +155,0 @@ } |
@@ -108,4 +108,3 @@ "use strict"; | ||
fix(fixer) { | ||
if (hasCommentsFirstToken || | ||
(0, yaml_1.hasTabIndent)(context)) { | ||
if (hasCommentsFirstToken || (0, yaml_1.hasTabIndent)(context)) { | ||
return null; | ||
@@ -146,10 +145,6 @@ } | ||
fix(fixer) { | ||
if (hasCommentsFirstToken || | ||
(0, yaml_1.hasTabIndent)(context)) { | ||
if (hasCommentsFirstToken || (0, yaml_1.hasTabIndent)(context)) { | ||
return null; | ||
} | ||
return fixer.removeRange([ | ||
openBrace.range[1], | ||
first.range[0], | ||
]); | ||
return fixer.removeRange([openBrace.range[1], first.range[0]]); | ||
}, | ||
@@ -173,6 +168,3 @@ }); | ||
} | ||
return fixer.removeRange([ | ||
last.range[1], | ||
closeBrace.range[0], | ||
]); | ||
return fixer.removeRange([last.range[1], closeBrace.range[0]]); | ||
}, | ||
@@ -179,0 +171,0 @@ }); |
@@ -93,6 +93,3 @@ "use strict"; | ||
} | ||
return fixer.removeRange([ | ||
token.range[1], | ||
nextToken.range[0], | ||
]); | ||
return fixer.removeRange([token.range[1], nextToken.range[0]]); | ||
}, | ||
@@ -116,6 +113,3 @@ }); | ||
} | ||
return fixer.removeRange([ | ||
previousToken.range[1], | ||
token.range[0], | ||
]); | ||
return fixer.removeRange([previousToken.range[1], token.range[0]]); | ||
}, | ||
@@ -171,8 +165,6 @@ }); | ||
elements.length > 0 && | ||
firstIncComment.loc.start.line !== | ||
lastIncComment.loc.end.line) || | ||
firstIncComment.loc.start.line !== lastIncComment.loc.end.line) || | ||
(elements.length === 0 && | ||
firstIncComment.type === "Block" && | ||
firstIncComment.loc.start.line !== | ||
lastIncComment.loc.end.line && | ||
firstIncComment.loc.start.line !== lastIncComment.loc.end.line && | ||
firstIncComment === lastIncComment) || | ||
@@ -179,0 +171,0 @@ (options.consistent && |
@@ -239,4 +239,3 @@ "use strict"; | ||
if (tokensOnSameLine.length === 0 || | ||
tokensOnSameLine[0].loc.start.line === | ||
token.loc.start.line) { | ||
tokensOnSameLine[0].loc.start.line === token.loc.start.line) { | ||
tokensOnSameLine.push(token); | ||
@@ -284,5 +283,3 @@ } | ||
next: nextToken, | ||
expectedOffset: nextExpectedIndent - | ||
expectedIndent - | ||
1, | ||
expectedOffset: nextExpectedIndent - expectedIndent - 1, | ||
actualOffset: nextToken.range[0] - token.range[1], | ||
@@ -369,4 +366,3 @@ }); | ||
} | ||
return (offset.expectedIndent = | ||
baseIndent + numOfIndent * offsetIndent); | ||
return (offset.expectedIndent = baseIndent + numOfIndent * offsetIndent); | ||
} | ||
@@ -672,6 +668,3 @@ function processMissingLines(lineIndents) { | ||
for (const markData of li.markData) { | ||
yield fixer.replaceTextRange([ | ||
markData.mark.range[1], | ||
markData.next.range[0], | ||
], " ".repeat(markData.expectedOffset)); | ||
yield fixer.replaceTextRange([markData.mark.range[1], markData.next.range[0]], " ".repeat(markData.expectedOffset)); | ||
} | ||
@@ -678,0 +671,0 @@ } |
@@ -197,4 +197,3 @@ "use strict"; | ||
} | ||
if (property.key.type === "YAMLWithMeta" && | ||
property.key.value == null) { | ||
if (property.key.type === "YAMLWithMeta" && property.key.value == null) { | ||
return false; | ||
@@ -447,4 +446,3 @@ } | ||
const properties = group.filter(isKeyValueProperty); | ||
if (properties.length > 0 && | ||
isSingleLineProperties(properties)) { | ||
if (properties.length > 0 && isSingleLineProperties(properties)) { | ||
verifyListSpacing(properties, multiLineOptions); | ||
@@ -463,5 +461,3 @@ } | ||
return; | ||
verifySpacing(node, isSingleLine(node.parent) | ||
? singleLineOptions | ||
: multiLineOptions); | ||
verifySpacing(node, isSingleLine(node.parent) ? singleLineOptions : multiLineOptions); | ||
}, | ||
@@ -468,0 +464,0 @@ }; |
@@ -51,4 +51,3 @@ "use strict"; | ||
if (skipQuotedScalars && | ||
(node.style === "double-quoted" || | ||
node.style === "single-quoted")) { | ||
(node.style === "double-quoted" || node.style === "single-quoted")) { | ||
if (ALL_IRREGULARS.test(sourceCode.getText(node))) { | ||
@@ -82,5 +81,3 @@ removeWhitespaceError(node); | ||
if (skipComments) { | ||
sourceCode | ||
.getAllComments() | ||
.forEach(removeInvalidNodeErrorsInComment); | ||
sourceCode.getAllComments().forEach(removeInvalidNodeErrorsInComment); | ||
} | ||
@@ -87,0 +84,0 @@ for (const errorIndex of errorIndexes) { |
@@ -87,4 +87,3 @@ "use strict"; | ||
const next = node.value[index + 1]; | ||
if (next && | ||
(!next.trim() || next === "!" || next === "<")) { | ||
if (next && (!next.trim() || next === "!" || next === "<")) { | ||
return false; | ||
@@ -95,5 +94,3 @@ } | ||
} | ||
const parent = node.parent.type === "YAMLWithMeta" | ||
? node.parent.parent | ||
: node.parent; | ||
const parent = node.parent.type === "YAMLWithMeta" ? node.parent.parent : node.parent; | ||
if (parent.type === "YAMLPair") { | ||
@@ -113,4 +110,3 @@ if (parent.key === node) { | ||
function verifyAlways(node) { | ||
if (node.style !== "double-quoted" && | ||
node.style !== "single-quoted") { | ||
if (node.style !== "double-quoted" && node.style !== "single-quoted") { | ||
return; | ||
@@ -117,0 +113,0 @@ } |
@@ -55,7 +55,5 @@ "use strict"; | ||
} | ||
else if (node.style === "single-quoted" && | ||
prefer === "double") { | ||
else if (node.style === "single-quoted" && prefer === "double") { | ||
if (avoidEscape && | ||
(node.strValue.includes('"') || | ||
node.strValue.includes("\\"))) { | ||
(node.strValue.includes('"') || node.strValue.includes("\\"))) { | ||
return; | ||
@@ -62,0 +60,0 @@ } |
@@ -121,5 +121,3 @@ "use strict"; | ||
else { | ||
const keyPattern = o.keyPattern | ||
? new RegExp(o.keyPattern) | ||
: null; | ||
const keyPattern = o.keyPattern ? new RegExp(o.keyPattern) : null; | ||
const nestOrder = (_d = o.order) !== null && _d !== void 0 ? _d : {}; | ||
@@ -130,3 +128,3 @@ const type = (_e = nestOrder.type) !== null && _e !== void 0 ? _e : "asc"; | ||
parsedOrder.push({ | ||
test: (data) => keyPattern ? keyPattern.test(data.name) : true, | ||
test: (data) => (keyPattern ? keyPattern.test(data.name) : true), | ||
isValidNestOrder: buildValidatorFromType(type, insensitive, natural), | ||
@@ -415,6 +413,3 @@ }); | ||
if ((0, ast_utils_1.isComma)(afterCommaToken)) { | ||
removeRange = [ | ||
beforeCommaToken.range[1], | ||
afterCommaToken.range[1], | ||
]; | ||
removeRange = [beforeCommaToken.range[1], afterCommaToken.range[1]]; | ||
insertCode = sourceCode.text.slice(...removeRange); | ||
@@ -421,0 +416,0 @@ insertTargetToken = moveTargetBeforeToken; |
@@ -137,5 +137,3 @@ "use strict"; | ||
else { | ||
const valuePattern = o.valuePattern | ||
? new RegExp(o.valuePattern) | ||
: null; | ||
const valuePattern = o.valuePattern ? new RegExp(o.valuePattern) : null; | ||
const nestOrder = (_c = o.order) !== null && _c !== void 0 ? _c : {}; | ||
@@ -414,10 +412,4 @@ const type = (_d = nestOrder.type) !== null && _d !== void 0 ? _d : "asc"; | ||
entryStack = entryStack.upper; | ||
entryStack.anchors = new Set([ | ||
...entryStack.anchors, | ||
...anchors, | ||
]); | ||
entryStack.aliases = new Set([ | ||
...entryStack.aliases, | ||
...aliases, | ||
]); | ||
entryStack.anchors = new Set([...entryStack.anchors, ...anchors]); | ||
entryStack.aliases = new Set([...entryStack.aliases, ...aliases]); | ||
}, | ||
@@ -468,6 +460,3 @@ "YAMLSequence:exit"(node) { | ||
function getBlockEntryRange(data) { | ||
return [ | ||
getBlockEntryStartOffset(data), | ||
getBlockEntryEndOffset(data), | ||
]; | ||
return [getBlockEntryStartOffset(data), getBlockEntryEndOffset(data)]; | ||
} | ||
@@ -481,4 +470,3 @@ function getBlockEntryStartOffset(data) { | ||
if (comment && | ||
data.aroundTokens.before.loc.start.column <= | ||
comment.loc.start.column) { | ||
data.aroundTokens.before.loc.start.column <= comment.loc.start.column) { | ||
return comment.range[0]; | ||
@@ -485,0 +473,0 @@ } |
@@ -40,3 +40,2 @@ import type { JSONSchema4 } from "json-schema"; | ||
ruleName: string; | ||
replacedBy?: []; | ||
default?: "error" | "warn"; | ||
@@ -53,2 +52,3 @@ extensionRule: string | false; | ||
deprecated?: boolean; | ||
replacedBy?: string[]; | ||
type: "problem" | "suggestion" | "layout"; | ||
@@ -55,0 +55,0 @@ } |
@@ -7,2 +7,3 @@ "use strict"; | ||
exports.rules = void 0; | ||
const block_mapping_colon_indicator_newline_1 = __importDefault(require("../rules/block-mapping-colon-indicator-newline")); | ||
const block_mapping_question_indicator_newline_1 = __importDefault(require("../rules/block-mapping-question-indicator-newline")); | ||
@@ -12,2 +13,3 @@ const block_mapping_1 = __importDefault(require("../rules/block-mapping")); | ||
const block_sequence_1 = __importDefault(require("../rules/block-sequence")); | ||
const file_extension_1 = __importDefault(require("../rules/file-extension")); | ||
const flow_mapping_curly_newline_1 = __importDefault(require("../rules/flow-mapping-curly-newline")); | ||
@@ -35,2 +37,3 @@ const flow_mapping_curly_spacing_1 = __importDefault(require("../rules/flow-mapping-curly-spacing")); | ||
exports.rules = [ | ||
block_mapping_colon_indicator_newline_1.default, | ||
block_mapping_question_indicator_newline_1.default, | ||
@@ -40,2 +43,3 @@ block_mapping_1.default, | ||
block_sequence_1.default, | ||
file_extension_1.default, | ||
flow_mapping_curly_newline_1.default, | ||
@@ -42,0 +46,0 @@ flow_mapping_curly_spacing_1.default, |
@@ -190,4 +190,3 @@ "use strict"; | ||
const actualIndent = getActualIndent(contentNode, context); | ||
if (actualIndent != null && | ||
compareIndent(baseIndent, actualIndent) < 0) { | ||
if (actualIndent != null && compareIndent(baseIndent, actualIndent) < 0) { | ||
return; | ||
@@ -194,0 +193,0 @@ } |
{ | ||
"name": "eslint-plugin-yml", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "This ESLint plugin provides linting rules for YAML.", | ||
@@ -31,2 +31,5 @@ "main": "lib/index.js", | ||
"version": "env-cmd -e version npm run update && git add .", | ||
"version:ci": "env-cmd -e version-ci npm run update && changeset version", | ||
"prerelease": "npm run build", | ||
"release": "changeset publish", | ||
"update-fixtures": "npm run ts -- ./tools/update-fixtures.ts && npm run eslint-fix", | ||
@@ -64,3 +67,5 @@ "ts": "node -r esbuild-register", | ||
"devDependencies": { | ||
"@ota-meshi/eslint-plugin": "^0.11.0", | ||
"@changesets/changelog-github": "^0.4.6", | ||
"@changesets/cli": "^2.24.2", | ||
"@ota-meshi/eslint-plugin": "^0.12.0", | ||
"@types/debug": "^4.1.5", | ||
@@ -80,3 +85,3 @@ "@types/eslint": "^8.0.0", | ||
"env-cmd": "^10.1.0", | ||
"esbuild": "^0.14.1", | ||
"esbuild": "^0.15.0", | ||
"esbuild-register": "^3.2.0", | ||
@@ -99,3 +104,3 @@ "eslint": "^8.0.0", | ||
"mocha": "^10.0.0", | ||
"monaco-editor": "^0.33.0", | ||
"monaco-editor": "^0.34.0", | ||
"nyc": "^15.1.0", | ||
@@ -107,5 +112,5 @@ "prettier": "^2.2.1", | ||
"stylelint-config-recommended-vue": "^1.0.0", | ||
"stylelint-config-standard": "^26.0.0", | ||
"stylelint-stylus": "^0.16.1", | ||
"typescript": "~4.7.0", | ||
"stylelint-config-standard": "^28.0.0", | ||
"stylelint-stylus": "^0.17.0", | ||
"typescript": "~4.8.0", | ||
"vue-eslint-editor": "^1.1.0", | ||
@@ -115,3 +120,6 @@ "vue-eslint-parser": "^9.0.0", | ||
"yaml": "^2.1.1" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
} | ||
} |
@@ -197,2 +197,3 @@ # Introduction | ||
|:--------|:------------|:-------:|:-----------:|:--------:| | ||
| [yml/block-mapping-colon-indicator-newline](https://ota-meshi.github.io/eslint-plugin-yml/rules/block-mapping-colon-indicator-newline.html) | enforce consistent line breaks after `:` indicator | :wrench: | | | | ||
| [yml/block-mapping-question-indicator-newline](https://ota-meshi.github.io/eslint-plugin-yml/rules/block-mapping-question-indicator-newline.html) | enforce consistent line breaks after `?` indicator | :wrench: | | :star: | | ||
@@ -202,2 +203,3 @@ | [yml/block-mapping](https://ota-meshi.github.io/eslint-plugin-yml/rules/block-mapping.html) | require or disallow block style mappings. | :wrench: | | :star: | | ||
| [yml/block-sequence](https://ota-meshi.github.io/eslint-plugin-yml/rules/block-sequence.html) | require or disallow block style sequences. | :wrench: | | :star: | | ||
| [yml/file-extension](https://ota-meshi.github.io/eslint-plugin-yml/rules/file-extension.html) | enforce YAML file extension | | | | | ||
| [yml/indent](https://ota-meshi.github.io/eslint-plugin-yml/rules/indent.html) | enforce consistent indentation | :wrench: | | :star: | | ||
@@ -204,0 +206,0 @@ | [yml/key-name-casing](https://ota-meshi.github.io/eslint-plugin-yml/rules/key-name-casing.html) | enforce naming convention to key names | | | | |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
246304
79
5862
283
49