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

@markuplint/ml-config

Package Overview
Dependencies
Maintainers
1
Versions
137
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@markuplint/ml-config - npm Package Compare versions

Comparing version 3.0.0-dev.96 to 3.0.0-dev.176

test/merge-config.spec.js

3

lib/merge-config.d.ts

@@ -1,3 +0,4 @@

import type { Config, Nullable, AnyRule, AnyRuleV2 } from './types';
import type { Config, AnyRule, AnyRuleV2 } from './types';
import type { Nullable } from '@markuplint/shared';
export declare function mergeConfig(a: Config, b: Config): Config;
export declare function mergeRule(a: Nullable<AnyRule | AnyRuleV2>, b: AnyRule | AnyRuleV2): AnyRule;

@@ -52,3 +52,3 @@ "use strict";

}
const value = Array.isArray(oA.value) && Array.isArray(b) ? [...oA.value, oB] : oB;
const value = Array.isArray(oA.value) && Array.isArray(oB) ? [...oA.value, ...oB] : oB;
const res = (0, utils_1.cleanOptions)({ ...oA, value });

@@ -74,6 +74,6 @@ (0, utils_1.deleteUndefProp)(res);

if (a == null) {
return b || undefined;
return b !== null && b !== void 0 ? b : undefined;
}
if (b == null) {
return a || undefined;
return a !== null && a !== void 0 ? a : undefined;
}

@@ -140,3 +140,3 @@ const res = (0, deepmerge_1.default)(a, b);

if (b == null) {
return a && optimizeRules(a);
return optimizeRules(a);
}

@@ -151,3 +151,3 @@ const res = optimizeRules(a);

(0, utils_1.deleteUndefProp)(res);
return res;
return Object.freeze(res);
}

@@ -154,0 +154,0 @@ function optimizeRules(rules) {

import type { ParserOptions } from '@markuplint/ml-ast';
import type { RegexSelector } from '@markuplint/selector';
import type { Nullable } from '@markuplint/shared';
export type { RegexSelector } from '@markuplint/selector';
export interface Config {
$schema?: string;
extends?: string | string[];
plugins?: (PluginConfig | string)[];
parser?: ParserConfig;
parserOptions?: ParserOptions;
specs?: SpecConfig;
excludeFiles?: string[];
pretenders?: Pretender[];
rules?: Rules;
nodeRules?: NodeRule[];
childNodeRules?: ChildNodeRule[];
overrides?: Record<string, Omit<Config, '$schema' | 'extends' | 'overrides'>>;
}
export type Config = {
readonly $schema?: string;
readonly extends?: string | readonly string[];
readonly plugins?: readonly (PluginConfig | string)[];
readonly parser?: ParserConfig;
readonly parserOptions?: ParserOptions;
readonly specs?: SpecConfig;
readonly excludeFiles?: readonly string[];
readonly pretenders?: readonly Pretender[];
readonly rules?: Rules;
readonly nodeRules?: readonly NodeRule[];
readonly childNodeRules?: readonly ChildNodeRule[];
readonly overrides?: Readonly<Record<string, OverrideConfig>>;
};
export type PrimitiveScalar = string | number | boolean;
export type PlainData =
| Nullable<PrimitiveScalar>
| readonly PlainData[]
| {
readonly [key: string]: PlainData | any;
};
export type NonNullablePlainData =
| PrimitiveScalar
| readonly NonNullablePlainData[]
| {
readonly [key: string]: NonNullablePlainData;
};
export type OverrideConfig = Omit<Config, '$schema' | 'extends' | 'overrides'>;
export type PluginConfig = {
name: string;
settings: Record<string, any>;
readonly name: string;
readonly settings: Readonly<Record<string, NonNullablePlainData>>;
};
export interface ParserConfig {
[extensionPattern: string]: string;
}
export type ParserConfig = {
readonly [extensionPattern: string]: string;
};
export type SpecConfig = {
[extensionPattern: string]: string;
readonly [extensionPattern: string]: string;
};
export type Pretender = {
/**
* Target node selectors
*/
selector: string;
/**
* If it is a string, it is resolved as an element name.
* An element has the same attributes as the pretended custom element
* because attributes are just inherited.
*
* If it is an Object, It creates the element by that.
*/
as: string | OriginalNode;
/**
* Target node selectors
*/
readonly selector: string;
/**
* If it is a string, it is resolved as an element name.
* An element has the same attributes as the pretended custom element
* because attributes are just inherited.
*
* If it is an Object, It creates the element by that.
*/
readonly as: string | OriginalNode;
};
export type OriginalNode = {
/**
* Element name
*/
element: string;
/**
* Namespace
*
* Supports `"svg"` and `undefined` only.
* If it is `undefined`, the namespace is HTML.
*/
namespace?: 'svg';
/**
* Attributes
*/
attrs?: {
/**
* Attribute name
*/
name: string;
/**
* If it omits this property, the attribute is resolved as a boolean.
*/
value?: string | {
fromAttr: string;
};
}[];
/**
* To have attributes the defined element has.
*/
inheritAttrs?: boolean;
/**
* ARIA properties
*/
aria?: PretenderARIA;
/**
* Element name
*/
readonly element: string;
/**
* Namespace
*
* Supports `"svg"` and `undefined` only.
* If it is `undefined`, the namespace is HTML.
*/
readonly namespace?: 'svg';
/**
* Attributes
*/
readonly attrs?: readonly {
/**
* Attribute name
*/
readonly name: string;
/**
* If it omits this property, the attribute is resolved as a boolean.
*/
readonly value?:
| string
| {
readonly fromAttr: string;
};
}[];
/**
* To have attributes the defined element has.
*/
readonly inheritAttrs?: boolean;
/**
* ARIA properties
*/
readonly aria?: PretenderARIA;
};

@@ -82,99 +99,106 @@ /**

export type PretenderARIA = {
/**
* Accessible name
*
* - If it is `true`, it assumes the element has any text on its accessible name.
* - If it specifies `fromAttr` property, it assumes the accessible name refers to the value of the attribute.
*/
name?: boolean | {
fromAttr: string;
};
/**
* Accessible name
*
* - If it is `true`, it assumes the element has any text on its accessible name.
* - If it specifies `fromAttr` property, it assumes the accessible name refers to the value of the attribute.
*/
readonly name?:
| boolean
| {
readonly fromAttr: string;
};
};
export type Rule<T extends RuleConfigValue, O = void> = RuleConfig<T, O> | T | boolean;
export type Rule<T extends RuleConfigValue, O extends PlainData = undefined> = RuleConfig<T, O> | Readonly<T> | boolean;
/**
* @deprecated
*/
export type RuleV2<T extends RuleConfigValue, O = void> = RuleConfigV2<T, O> | T | boolean;
export type AnyRule = Rule<RuleConfigValue, unknown>;
export type RuleV2<T extends RuleConfigValue, O extends PlainData = undefined> =
| RuleConfigV2<T, O>
| Readonly<T>
| boolean;
export type AnyRule = Rule<RuleConfigValue, PlainData>;
/**
* @deprecated
*/
export type AnyRuleV2 = RuleV2<RuleConfigValue, unknown>;
export interface Rules {
[ruleName: string]: AnyRule;
}
export type RuleConfig<T extends RuleConfigValue, O = void> = {
severity?: Severity;
value?: T;
options?: O;
reason?: string;
export type AnyRuleV2 = RuleV2<RuleConfigValue, PlainData>;
export type Rules = {
readonly [ruleName: string]: AnyRule;
};
export type RuleConfig<T extends RuleConfigValue, O extends PlainData = undefined> = {
readonly severity?: Severity;
readonly value?: Readonly<T>;
readonly options?: Readonly<O>;
readonly reason?: string;
};
/**
* @deprecated
*/
export type RuleConfigV2<T extends RuleConfigValue, O = void> = {
severity?: Severity;
value?: T;
reason?: string;
/**
* Old property
*
* @deprecated
* @see {this.options}
*/
option?: O;
export type RuleConfigV2<T extends RuleConfigValue, O extends PlainData = undefined> = {
readonly severity?: Severity;
readonly value?: Readonly<T>;
readonly reason?: string;
/**
* Old property
*
* @deprecated
* @see {this.options}
*/
readonly option?: Readonly<O>;
};
export type Severity = 'error' | 'warning' | 'info';
export type RuleConfigValue = string | number | boolean | any[] | null;
export interface NodeRule {
selector?: string;
regexSelector?: RegexSelector;
categories?: string[];
roles?: string[];
obsolete?: boolean;
rules?: Rules;
}
export interface ChildNodeRule {
selector?: string;
regexSelector?: RegexSelector;
inheritance?: boolean;
rules?: Rules;
}
export type Report<T extends RuleConfigValue, O = null> = Report1<T, O> | Report2 | (Report1<T, O> & Report2);
export type Report1<T extends RuleConfigValue, O = null> = {
message: string;
scope: Scope<T, O>;
export type RuleConfigValue = PrimitiveScalar | readonly (PrimitiveScalar | Readonly<Record<string, any>>)[] | null;
export type NodeRule = {
readonly selector?: string;
readonly regexSelector?: RegexSelector;
readonly categories?: readonly string[];
readonly roles?: readonly string[];
readonly obsolete?: boolean;
readonly rules?: Rules;
};
export type ChildNodeRule = {
readonly selector?: string;
readonly regexSelector?: RegexSelector;
readonly inheritance?: boolean;
readonly rules?: Rules;
};
export type Report<T extends RuleConfigValue, O extends PlainData = undefined> =
| Report1<T, O>
| Report2
| (Report1<T, O> & Report2);
export type Report1<T extends RuleConfigValue, O extends PlainData = undefined> = {
readonly message: string;
readonly scope: Scope<T, O>;
};
export type Report2 = {
message: string;
line: number;
col: number;
raw: string;
readonly message: string;
readonly line: number;
readonly col: number;
readonly raw: string;
};
export type Scope<T extends RuleConfigValue, O = null> = {
rule: RuleInfo<T, O>;
startLine: number;
startCol: number;
raw: string;
export type Scope<T extends RuleConfigValue, O extends PlainData = undefined> = {
readonly rule: RuleInfo<T, O>;
readonly startLine: number;
readonly startCol: number;
readonly raw: string;
};
export interface Violation {
ruleId: string;
severity: Severity;
message: string;
reason?: string;
line: number;
col: number;
raw: string;
}
export interface RuleInfo<T extends RuleConfigValue, O = null> {
disabled: boolean;
severity: Severity;
value: T;
options: O;
reason?: string;
}
export type GlobalRuleInfo<T extends RuleConfigValue, O = null> = RuleInfo<T, O> & {
nodeRules: RuleInfo<T, O>[];
childNodeRules: RuleInfo<T, O>[];
export type Violation = {
readonly ruleId: string;
readonly severity: Severity;
readonly message: string;
readonly reason?: string;
readonly line: number;
readonly col: number;
readonly raw: string;
};
export type Nullable<T> = T | null | undefined;
export type RuleInfo<T extends RuleConfigValue, O extends PlainData = undefined> = {
readonly disabled: boolean;
readonly severity: Severity;
readonly value: Readonly<T>;
readonly options: Readonly<O>;
readonly reason?: string;
};
export type GlobalRuleInfo<T extends RuleConfigValue, O extends PlainData = undefined> = RuleInfo<T, O> & {
nodeRules: RuleInfo<T, O>[];
childNodeRules: RuleInfo<T, O>[];
};

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

import type { AnyRule, AnyRuleV2, RuleConfig, RuleConfigV2, RuleConfigValue } from './types';
import type { AnyRule, AnyRuleV2, PlainData, RuleConfig, RuleConfigV2, RuleConfigValue } from './types';
/**

@@ -9,5 +9,10 @@ * Return undefined if the template doesn't include the variable that is set as a property in data.

*/
export declare function provideValue(template: string, data: Record<string, string>): string | undefined;
export declare function exchangeValueOnRule(rule: AnyRule | AnyRuleV2, data: Record<string, string>): AnyRule | undefined;
export declare function cleanOptions(rule: RuleConfig<RuleConfigValue, unknown> | RuleConfigV2<RuleConfigValue, unknown>): RuleConfig<RuleConfigValue, unknown>;
export declare function provideValue(template: string, data: Readonly<Record<string, string>>): string | undefined;
export declare function exchangeValueOnRule(
rule: AnyRule | AnyRuleV2,
data: Readonly<Record<string, string>>,
): AnyRule | undefined;
export declare function cleanOptions(
rule: RuleConfig<RuleConfigValue, PlainData> | RuleConfigV2<RuleConfigValue, PlainData>,
): RuleConfig<RuleConfigValue, PlainData>;
export declare function isRuleConfigValue(v: any): v is RuleConfigValue;

@@ -14,0 +19,0 @@ /**

@@ -15,4 +15,5 @@ "use strict";

function provideValue(template, data) {
var _a;
const ast = mustache_1.default.parse(template);
if (ast.length === 1 && ast[0][0] === 'text') {
if (ast.length === 1 && ((_a = ast[0]) === null || _a === void 0 ? void 0 : _a[0]) === 'text') {
// It doesn't have a variable

@@ -42,6 +43,11 @@ return template;

const options = extractOptions(result);
if (options) {
if (options != null && options !== '' && options !== 0) {
const newOptions = exchangeOption(options, data);
result = {
...result,
options: exchangeOption(options, data),
...(newOptions == null
? undefined
: {
options: newOptions,
}),
};

@@ -53,3 +59,3 @@ }

...result,
reason: exchangedValue ? `${exchangedValue}` : undefined,
reason: exchangedValue != null ? `${exchangedValue}` : undefined,
};

@@ -109,6 +115,6 @@ }

function extractOptions(rule) {
if ('options' in rule && rule.options) {
if ('options' in rule && rule.options != null) {
return rule.options;
}
if ('option' in rule && rule.option) {
if ('option' in rule && rule.option != null) {
return rule.option;

@@ -132,4 +138,4 @@ }

})
.filter(item => item !== undefined);
return ruleArray.length ? ruleArray : undefined;
.filter((item) => item !== undefined);
return ruleArray.length > 0 ? ruleArray : undefined;
}

@@ -148,3 +154,3 @@ return rule;

}
if (Array.isArray(optionValue)) {
if (isArray(optionValue)) {
return optionValue.map(v => exchangeOption(v, data));

@@ -158,1 +164,14 @@ }

}
/**
* Array.isArray for ReadonlyArray
*
* > Array.isArray type narrows to any[] for ReadonlyArray<T>
*
* @see https://github.com/microsoft/TypeScript/issues/17002
*
* @param value
* @returns
*/
function isArray(value) {
return Array.isArray(value);
}
{
"name": "@markuplint/ml-config",
"version": "3.0.0-dev.96+3b9f1720",
"version": "3.0.0-dev.176+f6ad62e9",
"description": "JSON Schema and TypeScript types of markuplint configure JSON",

@@ -21,13 +21,13 @@ "repository": "git@github.com:markuplint/markuplint.git",

},
"devDependencies": {
"@markuplint/ml-ast": "3.0.0-dev.96+3b9f1720",
"@types/mustache": "^4.2.2"
},
"dependencies": {
"@markuplint/selector": "3.0.0-dev.96+3b9f1720",
"deepmerge": "^4.2.2",
"@markuplint/ml-ast": "3.0.0-dev.176+f6ad62e9",
"@markuplint/selector": "3.0.0-dev.176+f6ad62e9",
"@markuplint/shared": "3.5.1-dev.3129+f6ad62e9",
"@types/mustache": "^4.2.2",
"deepmerge": "^4.3.1",
"is-plain-object": "^5.0.0",
"mustache": "^4.2.0"
"mustache": "^4.2.0",
"type-fest": "^3.8.0"
},
"gitHead": "3b9f17205d7754b29edf790bdbbf5e4931ba27a2"
"gitHead": "f6ad62e992e1569be4067f1e90d2d6017a658f57"
}
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