Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

eslint-plugin-yml

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-yml - npm Package Compare versions

Comparing version 1.2.0 to 1.3.0

86

lib/rules/indent.js

@@ -9,2 +9,16 @@ "use strict";

});
function parseOptions(context) {
const [indentOption, objectOptions] = context.options;
const numOfIndent = (0, yaml_1.getNumOfIndent)(context, indentOption);
let indentBlockSequences = true;
if (objectOptions) {
if (objectOptions.indentBlockSequences === false) {
indentBlockSequences = false;
}
}
return {
numOfIndent,
indentBlockSequences,
};
}
exports.default = (0, utils_1.createRule)("indent", {

@@ -24,2 +38,9 @@ meta: {

},
{
type: "object",
properties: {
indentBlockSequences: { type: "boolean" },
},
additionalProperties: false,
},
],

@@ -38,3 +59,3 @@ messages: {

}
const numOfIndent = (0, yaml_1.getNumOfIndent)(context, context.options[0]);
const { numOfIndent, indentBlockSequences } = parseOptions(context);
const sourceCode = context.getSourceCode();

@@ -95,2 +116,11 @@ const offsets = new Map();

}
function calcMappingPairValueIndentOffset(node) {
if (indentBlockSequences || !node) {
return 1;
}
if (node.type === "YAMLSequence" && node.style === "block") {
return 0;
}
return 1;
}
const documents = [];

@@ -145,34 +175,12 @@ return {

const pairFirst = sourceCode.getFirstToken(node);
let questionToken = null;
let keyToken = null;
let colonToken = null;
let valueToken = null;
if ((0, ast_utils_1.isQuestion)(pairFirst)) {
questionToken = pairFirst;
const keyToken = node.key && sourceCode.getFirstToken(node.key);
const colonToken = findColonToken();
const valueToken = node.value && sourceCode.getFirstToken(node.value);
const questionToken = (0, ast_utils_1.isQuestion)(pairFirst) ? pairFirst : null;
if (questionToken) {
marks.add(questionToken);
}
if (node.value) {
valueToken = sourceCode.getFirstToken(node.value);
colonToken = sourceCode.getTokenBefore(node.value, ast_utils_1.isColon);
}
if (node.key) {
keyToken = sourceCode.getFirstToken(node.key);
if (!colonToken) {
const token = sourceCode.getTokenAfter(node.key, ast_utils_1.isColon);
if (token && token.range[0] < node.range[1]) {
colonToken = token;
}
if (keyToken) {
setOffset(keyToken, calcMappingPairValueIndentOffset(node.key), questionToken);
}
}
if (!colonToken) {
const tokens = sourceCode.getTokens(node, ast_utils_1.isColon);
if (tokens.length) {
colonToken = tokens[0];
}
}
if (keyToken) {
if (questionToken) {
setOffset(keyToken, 1, questionToken);
}
}
if (colonToken) {

@@ -191,3 +199,3 @@ marks.add(colonToken);

if (colonToken) {
setOffset(valueToken, 1, colonToken);
setOffset(valueToken, calcMappingPairValueIndentOffset(node.value), colonToken);
}

@@ -198,2 +206,18 @@ else if (keyToken) {

}
function findColonToken() {
if (node.value) {
return sourceCode.getTokenBefore(node.value, ast_utils_1.isColon);
}
if (node.key) {
const token = sourceCode.getTokenAfter(node.key, ast_utils_1.isColon);
if (token && token.range[0] < node.range[1]) {
return token;
}
}
const tokens = sourceCode.getTokens(node, ast_utils_1.isColon);
if (tokens.length) {
return tokens[0];
}
return null;
}
},

@@ -200,0 +224,0 @@ YAMLWithMeta(node) {

@@ -27,2 +27,6 @@ "use strict";

class YAMLPairData {
get reportLoc() {
var _a, _b;
return (_b = (_a = this.node.key) === null || _a === void 0 ? void 0 : _a.loc) !== null && _b !== void 0 ? _b : this.node.loc;
}
constructor(mapping, node, index, anchorAlias) {

@@ -35,6 +39,2 @@ this.cachedName = null;

}
get reportLoc() {
var _a, _b;
return (_b = (_a = this.node.key) === null || _a === void 0 ? void 0 : _a.loc) !== null && _b !== void 0 ? _b : this.node.loc;
}
get name() {

@@ -41,0 +41,0 @@ var _a;

@@ -11,11 +11,2 @@ "use strict";

class YAMLEntryData {
constructor(sequence, node, index, anchorAlias) {
this.cached = null;
this.cachedRange = null;
this.cachedAroundTokens = null;
this.sequence = sequence;
this.node = node;
this.index = index;
this.anchorAlias = anchorAlias;
}
get reportLoc() {

@@ -61,2 +52,11 @@ if (this.node) {

}
constructor(sequence, node, index, anchorAlias) {
this.cached = null;
this.cachedRange = null;
this.cachedAroundTokens = null;
this.sequence = sequence;
this.node = node;
this.index = index;
this.anchorAlias = anchorAlias;
}
get value() {

@@ -63,0 +63,0 @@ var _a;

@@ -78,3 +78,3 @@ import type { JSONSchema4 } from "json-schema";

}
export declare type YMLSettings = {
export type YMLSettings = {
indent?: number;

@@ -102,4 +102,4 @@ };

}
export declare type YAMLToken = AST.Token | AST.Comment;
export declare type YAMLNodeOrToken = AST.YAMLNode | YAMLToken;
export type YAMLToken = AST.Token | AST.Comment;
export type YAMLNodeOrToken = AST.YAMLNode | YAMLToken;
export interface SourceCode {

@@ -154,4 +154,4 @@ text: string;

}
declare type FilterPredicate = (tokenOrComment: YAMLToken) => boolean;
declare type CursorWithSkipOptions = number | FilterPredicate | {
type FilterPredicate = (tokenOrComment: YAMLToken) => boolean;
type CursorWithSkipOptions = number | FilterPredicate | {
includeComments?: boolean;

@@ -161,3 +161,3 @@ filter?: FilterPredicate;

};
declare type CursorWithCountOptions = number | FilterPredicate | {
type CursorWithCountOptions = number | FilterPredicate | {
includeComments?: boolean;

@@ -173,3 +173,3 @@ filter?: FilterPredicate;

}
declare type SuggestionDescriptorMessage = {
type SuggestionDescriptorMessage = {
desc: string;

@@ -179,8 +179,8 @@ } | {

};
declare type SuggestionReportDescriptor = SuggestionDescriptorMessage & ReportDescriptorOptionsBase;
type SuggestionReportDescriptor = SuggestionDescriptorMessage & ReportDescriptorOptionsBase;
interface ReportDescriptorOptions extends ReportDescriptorOptionsBase {
suggest?: SuggestionReportDescriptor[] | null;
}
declare type ReportDescriptor = ReportDescriptorMessage & ReportDescriptorLocation & ReportDescriptorOptions;
declare type ReportDescriptorMessage = {
type ReportDescriptor = ReportDescriptorMessage & ReportDescriptorLocation & ReportDescriptorOptions;
type ReportDescriptorMessage = {
message: string;

@@ -190,3 +190,3 @@ } | {

};
declare type ReportDescriptorLocation = {
type ReportDescriptorLocation = {
node: YAMLNodeOrToken;

@@ -193,0 +193,0 @@ } | {

@@ -1,2 +0,2 @@

export declare type CasingKind = "camelCase" | "kebab-case" | "PascalCase" | "snake_case" | "SCREAMING_SNAKE_CASE";
export type CasingKind = "camelCase" | "kebab-case" | "PascalCase" | "snake_case" | "SCREAMING_SNAKE_CASE";
export declare const allowedCaseOptions: CasingKind[];

@@ -3,0 +3,0 @@ export declare function kebabCase(str: string): string;

@@ -5,3 +5,3 @@ import type { RuleListener, RuleModule, PartialRuleModule, RuleContext } from "../types";

export declare function createRule(ruleName: string, rule: PartialRuleModule): RuleModule;
declare type CoreRuleListener = {
type CoreRuleListener = {
[key: string]: (node: any) => void;

@@ -8,0 +8,0 @@ };

{
"name": "eslint-plugin-yml",
"version": "1.2.0",
"version": "1.3.0",
"description": "This ESLint plugin provides linting rules for YAML.",

@@ -68,3 +68,3 @@ "main": "lib/index.js",

"@changesets/cli": "^2.24.2",
"@ota-meshi/eslint-plugin": "^0.12.0",
"@ota-meshi/eslint-plugin": "^0.13.0",
"@types/debug": "^4.1.5",

@@ -76,5 +76,5 @@ "@types/eslint": "^8.0.0",

"@types/lodash": "^4.14.158",
"@types/mocha": "^9.0.0",
"@types/mocha": "^10.0.0",
"@types/natural-compare": "^1.4.0",
"@types/node": "^16.11.3",
"@types/node": "^18.0.0",
"@types/semver": "^7.3.1",

@@ -95,3 +95,3 @@ "@typescript-eslint/eslint-plugin": "^5.0.0",

"eslint-plugin-node": "^11.1.0",
"eslint-plugin-node-dependencies": "^0.9.0",
"eslint-plugin-node-dependencies": "^0.10.0",
"eslint-plugin-prettier": "^4.0.0",

@@ -111,5 +111,5 @@ "eslint-plugin-regexp": "^1.0.0",

"stylelint-config-recommended-vue": "^1.0.0",
"stylelint-config-standard": "^28.0.0",
"stylelint-config-standard": "^29.0.0",
"stylelint-stylus": "^0.17.0",
"typescript": "~4.8.0",
"typescript": "~4.9.0",
"vue-eslint-editor": "^1.1.0",

@@ -116,0 +116,0 @@ "vue-eslint-parser": "^9.0.0",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc