eslint-plugin-yml
Advanced tools
Comparing version 0.12.0 to 0.13.0
@@ -68,3 +68,3 @@ "use strict"; | ||
return options.map((opt) => { | ||
var _a, _b, _c; | ||
var _a, _b, _c, _d, _e; | ||
const order = opt.order; | ||
@@ -86,9 +86,43 @@ const pathPattern = new RegExp(opt.pathPattern); | ||
} | ||
const parsedOrder = []; | ||
for (const o of order) { | ||
if (typeof o === "string") { | ||
parsedOrder.push({ | ||
test: (s) => s === o, | ||
isValidNestOrder: () => true, | ||
}); | ||
} | ||
else { | ||
const keyPattern = o.keyPattern | ||
? new RegExp(o.keyPattern) | ||
: null; | ||
const nestOrder = (_d = o.order) !== null && _d !== void 0 ? _d : {}; | ||
const type = (_e = nestOrder.type) !== null && _e !== void 0 ? _e : "asc"; | ||
const insensitive = nestOrder.caseSensitive === false; | ||
const natural = Boolean(nestOrder.natural); | ||
parsedOrder.push({ | ||
test: (s) => (keyPattern ? keyPattern.test(s) : true), | ||
isValidNestOrder: buildValidatorFromType(type, insensitive, natural), | ||
}); | ||
} | ||
} | ||
return { | ||
isTargetMapping, | ||
ignore: (s) => !order.includes(s), | ||
ignore: (s) => parsedOrder.every((p) => !p.test(s)), | ||
isValidOrder(a, b) { | ||
const aIndex = order.indexOf(a); | ||
const bIndex = order.indexOf(b); | ||
return aIndex <= bIndex; | ||
for (const p of parsedOrder) { | ||
const matchA = p.test(a); | ||
const matchB = p.test(b); | ||
if (!matchA || !matchB) { | ||
if (matchA) { | ||
return true; | ||
} | ||
if (matchB) { | ||
return false; | ||
} | ||
continue; | ||
} | ||
return p.isValidNestOrder(a, b); | ||
} | ||
return false; | ||
}, | ||
@@ -132,3 +166,18 @@ minKeys, | ||
} | ||
const allowOrderTypes = ["asc", "desc"]; | ||
const ALLOW_ORDER_TYPES = ["asc", "desc"]; | ||
const ORDER_OBJECT_SCHEMA = { | ||
type: "object", | ||
properties: { | ||
type: { | ||
enum: ALLOW_ORDER_TYPES, | ||
}, | ||
caseSensitive: { | ||
type: "boolean", | ||
}, | ||
natural: { | ||
type: "boolean", | ||
}, | ||
}, | ||
additionalProperties: false, | ||
}; | ||
exports.default = (0, utils_1.createRule)("sort-keys", { | ||
@@ -159,20 +208,20 @@ meta: { | ||
type: "array", | ||
items: { type: "string" }, | ||
items: { | ||
anyOf: [ | ||
{ type: "string" }, | ||
{ | ||
type: "object", | ||
properties: { | ||
keyPattern: { | ||
type: "string", | ||
}, | ||
order: ORDER_OBJECT_SCHEMA, | ||
}, | ||
additionalProperties: false, | ||
}, | ||
], | ||
}, | ||
uniqueItems: true, | ||
}, | ||
{ | ||
type: "object", | ||
properties: { | ||
type: { | ||
enum: allowOrderTypes, | ||
}, | ||
caseSensitive: { | ||
type: "boolean", | ||
}, | ||
natural: { | ||
type: "boolean", | ||
}, | ||
}, | ||
additionalProperties: false, | ||
}, | ||
ORDER_OBJECT_SCHEMA, | ||
], | ||
@@ -194,3 +243,3 @@ }, | ||
{ | ||
enum: allowOrderTypes, | ||
enum: ALLOW_ORDER_TYPES, | ||
}, | ||
@@ -197,0 +246,0 @@ { |
{ | ||
"name": "eslint-plugin-yml", | ||
"version": "0.12.0", | ||
"version": "0.13.0", | ||
"description": "This ESLint plugin provides linting rules for YAML.", | ||
@@ -45,2 +45,3 @@ "main": "lib/index.js", | ||
"author": "Yosuke Ota", | ||
"funding": "https://github.com/sponsors/ota-meshi", | ||
"license": "MIT", | ||
@@ -88,7 +89,7 @@ "bugs": { | ||
"eslint-plugin-vue": "^8.0.0", | ||
"eslint-plugin-yml": "^0.11.0", | ||
"eslint-plugin-yml": "^0.12.0", | ||
"eslint4b": "^7.3.1", | ||
"espree": "^9.0.0", | ||
"mocha": "^9.0.0", | ||
"monaco-editor": "^0.30.0", | ||
"monaco-editor": "^0.31.0", | ||
"nyc": "^15.1.0", | ||
@@ -95,0 +96,0 @@ "prettier": "^2.2.1", |
@@ -149,2 +149,14 @@ # Introduction | ||
### JetBrains WebStorm IDEs | ||
In any of the JetBrains IDEs you can [configure the linting scope](https://www.jetbrains.com/help/webstorm/eslint.html#ws_eslint_configure_scope). | ||
Following the steps in their help document, you can add YAML files to the scope like so: | ||
1. Open the **Settings/Preferences** dialog, go to **Languages and Frameworks** | **JavaScript** | **Code Quality Tools** | **ESLint**, and select **Automatic ESLint configuration** or **Manual ESLint configuration**. | ||
2. In the **Run for files** field, update the pattern that defines the set of files to be linted to include YAML files as well: | ||
``` | ||
{**/*,*}.{js,ts,jsx,tsx,html,vue,yaml,yml} | ||
^^^^ ^^^ | ||
``` | ||
<!--USAGE_GUIDE_END--> | ||
@@ -151,0 +163,0 @@ <!--USAGE_SECTION_END--> |
218231
5193
260