eslint-plugin-yml
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -5,14 +5,6 @@ "use strict"; | ||
const yaml_1 = require("../utils/yaml"); | ||
const ast_utils_1 = require("../utils/ast-utils"); | ||
const ITERATION_OPTS = Object.freeze({ | ||
includeComments: true, | ||
}); | ||
function isQuestion(token) { | ||
return token != null && token.type === "Punctuator" && token.value === "?"; | ||
} | ||
function isHyphen(token) { | ||
return token != null && token.type === "Punctuator" && token.value === "-"; | ||
} | ||
function isColon(token) { | ||
return token != null && token.type === "Punctuator" && token.value === ":"; | ||
} | ||
exports.default = utils_1.createRule("indent", { | ||
@@ -134,3 +126,3 @@ meta: { | ||
for (const entry of node.entries) { | ||
const hyphen = sourceCode.getTokenBefore(entry, isHyphen); | ||
const hyphen = sourceCode.getTokenBefore(entry, ast_utils_1.isHyphen); | ||
marks.add(hyphen); | ||
@@ -148,3 +140,3 @@ const entryToken = sourceCode.getFirstToken(entry); | ||
let valueToken = null; | ||
if (isQuestion(pairFirst)) { | ||
if (ast_utils_1.isQuestion(pairFirst)) { | ||
questionToken = pairFirst; | ||
@@ -155,3 +147,3 @@ marks.add(questionToken); | ||
valueToken = sourceCode.getFirstToken(node.value); | ||
colonToken = sourceCode.getTokenBefore(node.value, isColon); | ||
colonToken = sourceCode.getTokenBefore(node.value, ast_utils_1.isColon); | ||
} | ||
@@ -161,3 +153,3 @@ if (node.key) { | ||
if (!colonToken) { | ||
const token = sourceCode.getTokenAfter(node.key, isColon); | ||
const token = sourceCode.getTokenAfter(node.key, ast_utils_1.isColon); | ||
if (token && token.range[0] < node.range[1]) { | ||
@@ -169,3 +161,3 @@ colonToken = token; | ||
if (!colonToken) { | ||
const tokens = sourceCode.getTokens(node, isColon); | ||
const tokens = sourceCode.getTokens(node, ast_utils_1.isColon); | ||
if (tokens.length) { | ||
@@ -172,0 +164,0 @@ colonToken = tokens[0]; |
@@ -12,3 +12,3 @@ "use strict"; | ||
categories: ["recommended"], | ||
extensionRule: true, | ||
extensionRule: "no-irregular-whitespace", | ||
}, | ||
@@ -37,2 +37,5 @@ schema: [ | ||
create(context) { | ||
if (!context.parserServices.isYAML) { | ||
return {}; | ||
} | ||
let errorIndexes = []; | ||
@@ -39,0 +42,0 @@ const options = context.options[0] || {}; |
@@ -56,3 +56,3 @@ "use strict"; | ||
categories: null, | ||
extensionRule: true, | ||
extensionRule: "spaced-comment", | ||
}, | ||
@@ -92,2 +92,5 @@ fixable: "whitespace", | ||
create(context) { | ||
if (!context.parserServices.isYAML) { | ||
return {}; | ||
} | ||
const sourceCode = context.getSourceCode(); | ||
@@ -94,0 +97,0 @@ const requireSpace = context.options[0] !== "never"; |
@@ -42,3 +42,3 @@ import type { JSONSchema4 } from "json-schema"; | ||
default?: "error" | "warn"; | ||
extensionRule: boolean; | ||
extensionRule: string | false; | ||
}; | ||
@@ -63,3 +63,3 @@ messages: { | ||
default?: "error" | "warn"; | ||
extensionRule: boolean; | ||
extensionRule: string | false; | ||
}; | ||
@@ -66,0 +66,0 @@ messages: { |
@@ -5,7 +5,11 @@ import type { RuleListener, RuleModule, PartialRuleModule, RuleContext } from "../types"; | ||
export declare function createRule(ruleName: string, rule: PartialRuleModule): RuleModule; | ||
declare type CoreRuleListener = { | ||
[key: string]: (node: any) => void; | ||
}; | ||
export declare function defineWrapperListener(coreRule: Rule.RuleModule, context: RuleContext, proxyOptions: { | ||
options: any[]; | ||
createListenerProxy?: (listener: RuleListener) => RuleListener; | ||
createListenerProxy?: (listener: CoreRuleListener) => RuleListener; | ||
}): RuleListener; | ||
export declare function getProxyNode(node: AST.YAMLNode, properties: any): any; | ||
export declare function isNode(data: any): boolean; | ||
export {}; |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isNode = exports.getProxyNode = exports.defineWrapperListener = exports.createRule = void 0; | ||
const debug_1 = __importDefault(require("debug")); | ||
const log = debug_1.default("eslint-plugin-yml:utils/index"); | ||
function createRule(ruleName, rule) { | ||
@@ -25,2 +30,6 @@ return { | ||
function getProxyNode(node, properties) { | ||
const safeKeys = new Set([ | ||
"range", | ||
"typeAnnotation", | ||
]); | ||
const cache = {}; | ||
@@ -35,2 +44,5 @@ return new Proxy(node, { | ||
} | ||
if (!safeKeys.has(key)) { | ||
log(`fallback: ${String(key)}`); | ||
} | ||
return node[key]; | ||
@@ -37,0 +49,0 @@ }, |
@@ -9,2 +9,6 @@ "use strict"; | ||
const block_sequence_1 = __importDefault(require("../rules/block-sequence")); | ||
const flow_mapping_curly_newline_1 = __importDefault(require("../rules/flow-mapping-curly-newline")); | ||
const flow_mapping_curly_spacing_1 = __importDefault(require("../rules/flow-mapping-curly-spacing")); | ||
const flow_sequence_bracket_newline_1 = __importDefault(require("../rules/flow-sequence-bracket-newline")); | ||
const flow_sequence_bracket_spacing_1 = __importDefault(require("../rules/flow-sequence-bracket-spacing")); | ||
const indent_1 = __importDefault(require("../rules/indent")); | ||
@@ -17,2 +21,6 @@ const no_irregular_whitespace_1 = __importDefault(require("../rules/no-irregular-whitespace")); | ||
block_sequence_1.default, | ||
flow_mapping_curly_newline_1.default, | ||
flow_mapping_curly_spacing_1.default, | ||
flow_sequence_bracket_newline_1.default, | ||
flow_sequence_bracket_spacing_1.default, | ||
indent_1.default, | ||
@@ -19,0 +27,0 @@ no_irregular_whitespace_1.default, |
@@ -9,2 +9,3 @@ import type { AST } from "yaml-eslint-parser"; | ||
export declare function incIndent(indent: string, context: RuleContext): string; | ||
export declare function decIndent(indent: string, context: RuleContext): string; | ||
export declare function getNumOfIndent(context: RuleContext, optionValue?: number | null): number; | ||
@@ -11,0 +12,0 @@ export declare function compareIndent(a: string, b: string): number; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.processIndentFix = exports.unwrapMeta = exports.isKeyNode = exports.compareIndent = exports.getNumOfIndent = exports.incIndent = exports.getActualIndentFromLine = exports.getActualIndent = exports.calcExpectIndentForEntries = exports.calcExpectIndentForPairs = exports.hasTabIndent = void 0; | ||
exports.processIndentFix = exports.unwrapMeta = exports.isKeyNode = exports.compareIndent = exports.getNumOfIndent = exports.decIndent = exports.incIndent = exports.getActualIndentFromLine = exports.getActualIndent = exports.calcExpectIndentForEntries = exports.calcExpectIndentForPairs = exports.hasTabIndent = void 0; | ||
function hasTabIndent(context) { | ||
@@ -134,8 +134,11 @@ for (const line of context.getSourceCode().getLines()) { | ||
? " " | ||
: numOfIndent <= 1 | ||
? " " | ||
: " ".repeat(numOfIndent); | ||
: " ".repeat(numOfIndent); | ||
return `${indent}${add}`; | ||
} | ||
exports.incIndent = incIndent; | ||
function decIndent(indent, context) { | ||
const numOfIndent = getNumOfIndent(context); | ||
return " ".repeat(indent.length - numOfIndent); | ||
} | ||
exports.decIndent = decIndent; | ||
function getNumOfIndent(context, optionValue) { | ||
@@ -142,0 +145,0 @@ var _a, _b; |
{ | ||
"name": "eslint-plugin-yml", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "This ESLint plugin provides linting rules for YAML.", | ||
@@ -17,2 +17,3 @@ "main": "lib/index.js", | ||
"pretest": "npm run setup-types", | ||
"pretest:base": "cross-env DEBUG=eslint-plugin-yml*", | ||
"test:base": "mocha --require ts-node/register \"tests/src/**/*.ts\" --reporter dot --timeout 60000", | ||
@@ -56,2 +57,3 @@ "test": "npm run test:base", | ||
"dependencies": { | ||
"debug": "^4.1.1", | ||
"lodash": "^4.17.19", | ||
@@ -62,2 +64,3 @@ "yaml-eslint-parser": "^0.0.7" | ||
"@mysticatea/eslint-plugin": "^13.0.0", | ||
"@types/debug": "^4.1.5", | ||
"@types/eslint": "^7.2.0", | ||
@@ -70,2 +73,3 @@ "@types/estree": "^0.0.44", | ||
"babel-eslint": "^10.1.0", | ||
"cross-env": "^7.0.2", | ||
"eslint": "^7.3.0", | ||
@@ -72,0 +76,0 @@ "eslint-plugin-jsonc": "^0.3.1", |
@@ -128,2 +128,6 @@ # Introduction | ||
|:--------|:------------|:-------:|:-----------:| | ||
| [yml/flow-mapping-curly-newline](https://ota-meshi.github.io/eslint-plugin-yml/rules/flow-mapping-curly-newline.html) | enforce consistent line breaks inside braces | :wrench: | | | ||
| [yml/flow-mapping-curly-spacing](https://ota-meshi.github.io/eslint-plugin-yml/rules/flow-mapping-curly-spacing.html) | enforce consistent spacing inside braces | :wrench: | | | ||
| [yml/flow-sequence-bracket-newline](https://ota-meshi.github.io/eslint-plugin-yml/rules/flow-sequence-bracket-newline.html) | enforce linebreaks after opening and before closing flow sequence brackets | :wrench: | | | ||
| [yml/flow-sequence-bracket-spacing](https://ota-meshi.github.io/eslint-plugin-yml/rules/flow-sequence-bracket-spacing.html) | enforce consistent spacing inside flow sequence brackets | :wrench: | | | ||
| [yml/no-irregular-whitespace](https://ota-meshi.github.io/eslint-plugin-yml/rules/no-irregular-whitespace.html) | disallow irregular whitespace | | :star: | | ||
@@ -130,0 +134,0 @@ | [yml/spaced-comment](https://ota-meshi.github.io/eslint-plugin-yml/rules/spaced-comment.html) | enforce consistent spacing after the `#` in a comment | :wrench: | | |
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
113735
39
2637
158
4
26
+ Addeddebug@^4.1.1