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

@linthtml/core

Package Overview
Dependencies
Maintainers
0
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@linthtml/core - npm Package Compare versions

Comparing version 0.10.0-beta.9 to 0.10.0-beta.10

dist/src/rules/link-label-min-length/index.d.ts

8

dist/package.json
{
"name": "@linthtml/core",
"version": "0.10.0-beta.9",
"version": "0.10.0-beta.10",
"description": "LintHTML core package",

@@ -56,4 +56,4 @@ "author": "BenjaminJ <kamikillerto@gmail.com>",

"dependencies": {
"@linthtml/dom-utils": "^0.10.0-beta.9",
"@linthtml/html-parser": "^0.10.0-beta.9",
"@linthtml/dom-utils": "^0.10.0-beta.10",
"@linthtml/html-parser": "^0.10.0-beta.10",
"bulk-require": "1.0.1",

@@ -76,5 +76,5 @@ "cosmiconfig": "^8.0.0",

},
"gitHead": "104449aaa57c5e77625a3395897facf09f26fbed",
"gitHead": "8d081aa52e63b3cd086c61f2e3dce04961a0f0f9",
"module": "./src/index.js",
"main": "./src/index.js"
}
import type { Range } from "@linthtml/dom-utils/dom_elements";
export declare const ISSUE_SEVERITY: {
ERROR: string;
WARNING: string;
};
export default class Issue {
code: string;
position: Range;
position: Range | null;
rule: string;
message: string;
data: Record<string, unknown>;
severity: "error" | "warning";
constructor(rule_name: string, position: Range, options: {
severity: (typeof ISSUE_SEVERITY)[keyof typeof ISSUE_SEVERITY];
constructor(rule_name: string, position: Range | null, options: {
code: string;

@@ -14,5 +18,5 @@ rule?: string;

data?: Record<string, unknown>;
severity?: "error" | "warning";
severity?: (typeof ISSUE_SEVERITY)[keyof typeof ISSUE_SEVERITY];
});
}
//# sourceMappingURL=issue.d.ts.map

@@ -0,1 +1,5 @@

export const ISSUE_SEVERITY = {
ERROR: "error",
WARNING: "warning"
};
export default class Issue {

@@ -6,3 +10,3 @@ // TODO: CHECK why options.rule (legacy, need to be removed)

this.data = {};
this.severity = "error";
this.severity = ISSUE_SEVERITY.ERROR;
this.position = position;

@@ -13,4 +17,4 @@ this.code = options.code;

this.data = options.data || {};
this.severity = options.severity || "error";
this.severity = options.severity || ISSUE_SEVERITY.ERROR;
}
}

@@ -5,3 +5,3 @@ import Config from "./config.js";

import type { Document } from "@linthtml/dom-utils/dom_elements";
import type Issue from "../issue.js";
import Issue from "../issue.js";
export default class Linter {

@@ -21,2 +21,3 @@ rules: Config;

lint(html: string): Promise<Issue[]>;
reportDeprecatedRules(): Issue[];
lintDom(dom: Document, opts: unknown): Issue[];

@@ -23,0 +24,0 @@ resetRules(opts?: unknown): Issue[];

@@ -5,2 +5,3 @@ import parse from "@linthtml/html-parser";

import rules from "../rules/index.js";
import Issue, { ISSUE_SEVERITY } from "../issue.js";
import { is_comment_node } from "@linthtml/dom-utils";

@@ -49,2 +50,3 @@ /**

const dom = parse(html);
issues = issues.concat(this.reportDeprecatedRules());
issues = issues.concat(this.setupInlineConfigs(dom));

@@ -62,2 +64,15 @@ try {

}
reportDeprecatedRules() {
var _a, _b;
return ((_b = (_a = this.rules
.getRule("dom")
.subscribers) === null || _a === void 0 ? void 0 : _a.filter(({ deprecated }) => deprecated).map((rule) => new Issue("", null, {
code: "DEPRECATED_RULE",
severity: ISSUE_SEVERITY.WARNING,
data: {
rule_name: rule.name,
hint: rule.deprecation_hint
}
}))) !== null && _b !== void 0 ? _b : []);
}
// Here ignore ts error as "dom" is special rule.

@@ -64,0 +79,0 @@ lintDom(dom, opts) {

@@ -12,2 +12,3 @@ import Config from "./config.js";

lint(html: string): Promise<Issue[]>;
private report_deprecated_rules;
private lint_DOM;

@@ -14,0 +15,0 @@ private call_rule_lint;

import Config from "./config.js";
import { extract_inline_config } from "./inline_config.js";
import rules from "./rules/index.js";
import Issue from "./issue.js";
import Issue, { ISSUE_SEVERITY } from "./issue.js";
import CustomError from "./utils/custom-errors.js";

@@ -71,4 +71,5 @@ import { get_module_path } from "./read-config.js";

const activated_rules = Object.keys(this.config.activated_rules).map((name) => this.config.activated_rules[name]);
const domIssues = this.lint_DOM(activated_rules, dom);
let issues = [...domIssues, ...this.reset_rules()];
const rules_deprecated_issues = this.report_deprecated_rules(activated_rules);
const dom_issues = this.lint_DOM(activated_rules, dom);
let issues = [...rules_deprecated_issues, ...dom_issues, ...this.reset_rules()];
if (this.config.config.maxerr) {

@@ -79,2 +80,14 @@ issues = issues.slice(0, this.config.config.maxerr); // REMOVE: After v1.

}
report_deprecated_rules(activated_rules) {
return activated_rules
.filter(({ deprecated }) => deprecated)
.map((rule) => new Issue("", null, {
code: "DEPRECATED_RULE",
severity: ISSUE_SEVERITY.WARNING,
data: {
rule_name: rule.name,
hint: rule.deprecation_hint
}
}));
}
lint_DOM(rules, dom) {

@@ -81,0 +94,0 @@ const issues = [];

@@ -154,2 +154,3 @@ import type { CharValue, Range } from "@linthtml/dom-utils/dom_elements";

content: string;
min_length: number;
}) => string;

@@ -163,2 +164,3 @@ readonly E060: () => string;

}) => string;
readonly E065: () => string;
readonly INLINE_01: (data: {

@@ -177,2 +179,6 @@ instruction: string;

}) => string;
readonly DEPRECATED_RULE: (data: {
rule_name: string;
hint?: string;
}) => string;
};

@@ -179,0 +185,0 @@ export declare function renderIssue(issue: Issue): string;

@@ -76,3 +76,3 @@ import chalkTemplate from "chalk-template";

E058: ( /* data */) => 'Links should with `target="blank"` should define `rel="noopener"`',
E059: (data) => `Link text should have at least 4 chars, current text "${data.content}" has a length of ${data.content.length}`,
E059: (data) => `Link text should have at least ${data.min_length} chars, current text "${data.content}" has a length of ${data.content.length}`,
E060: ( /* data */) => 'Input elements with type "button", "submit" and "reset" must have a value or title attribute.',

@@ -83,6 +83,8 @@ E061: ( /* data */) => "Each button element must have a text content.",

E064: (data) => `Unexpected space ${data.is_before ? "before" : "after"} text.`,
E065: ( /* data */) => "something something",
INLINE_01: (data) => `unrecognized linthtml instruction: \`linthtml-${data.instruction}\``,
INLINE_02: (data) => `unrecognized rule name \`${data.rule_name}\` in inline configuration`,
INLINE_03: (data) => `malformed linthtml-configure instruction: \`${data.rule_configuration}\` is not valid JSON global`,
INLINE_04: (data) => `linthtml-configure instruction for rule \`${data.rule_name}\` is not valid. ${data.error}`
INLINE_04: (data) => `linthtml-configure instruction for rule \`${data.rule_name}\` is not valid. ${data.error}`,
DEPRECATED_RULE: (data) => `Rule "${data.rule_name}" is deprecated.${data.hint ? ` ${data.hint}` : ""}`
};

@@ -89,0 +91,0 @@ // Error code INLINE-xx

@@ -13,2 +13,4 @@ import type Issue from "./issue.js";

name: string;
deprecated?: boolean;
deprecation_hint?: string;
lint: (node: Node, rule_config: unknown, obj: {

@@ -15,0 +17,0 @@ report: reportFunction;

@@ -31,3 +31,4 @@ import { is_tag_node } from "@linthtml/dom-utils";

name: RULE_NAME,
deprecated: true,
lint
};

@@ -24,4 +24,6 @@ import ClassStyleRule from "../class-style/index.js";

name: RULE_NAME,
deprecated: true,
deprecation_hint: 'Use the rules "id-style" and "class-style" instead.',
validateConfig: create_list_value_validator(RULE_NAME, ["lowercase", "underscore", "dash", "camel", "bem"]),
lint
};
declare const _default: {
name: string;
deprecated: true;
deprecation_hint: string;
lint(): void;

@@ -4,0 +6,0 @@ };

const RULE_NAME = "indent-delta";
export default {
name: RULE_NAME,
deprecated: true,
deprecation_hint: "This rule does nothing and should be removed from the config file",
// eslint-disable-next-line @typescript-eslint/no-empty-function
lint() { }
};
declare const _default: {
name: string;
deprecated: true;
lint(): void;

@@ -4,0 +5,0 @@ };

const RULE_NAME = "indent-width-cont";
export default {
name: RULE_NAME,
deprecated: true,
// eslint-disable-next-line @typescript-eslint/no-empty-function
lint() { }
};

@@ -1,35 +0,11 @@

import { is_tag_node, attribute_value, has_non_empty_attribute, is_comment_node, is_text_node } from "@linthtml/dom-utils";
import LinkLabelMinLengthRule from "../link-label-min-length/index.js";
const RULE_NAME = "link-min-length-4";
function get_text_content(node) {
if (is_comment_node(node)) {
return "";
}
if (is_text_node(node)) {
return node.data;
}
return node.children.reduce((content, child) => `${content}${get_text_content(child)}`, "");
function lint(node, _config, obj) {
return LinkLabelMinLengthRule.lint(node, 4, obj);
}
function lint(node, _config, { report }) {
var _a, _b;
// Will add a rule to enforce href attribute on link
if (is_tag_node(node) && node.name === "a" && has_non_empty_attribute(node, "href")) {
const content = get_text_content(node).trim();
const aria_label = (_b = (_a = attribute_value(node, "aria-label")) === null || _a === void 0 ? void 0 : _a.chars) !== null && _b !== void 0 ? _b : "";
// TODO: need to deal with aria-labelledby
if (content.length < 4 && aria_label.length < 4) {
report({
code: "E059",
position: node.open.loc,
meta: {
data: {
content
}
}
});
}
}
}
export default {
name: RULE_NAME,
deprecated: true,
deprecation_hint: 'Use rule "link-label-min-length" instead.',
lint
};
{
"name": "@linthtml/core",
"version": "0.10.0-beta.9",
"version": "0.10.0-beta.10",
"description": "LintHTML core package",

@@ -56,4 +56,4 @@ "author": "BenjaminJ <kamikillerto@gmail.com>",

"dependencies": {
"@linthtml/dom-utils": "^0.10.0-beta.9",
"@linthtml/html-parser": "^0.10.0-beta.9",
"@linthtml/dom-utils": "^0.10.0-beta.10",
"@linthtml/html-parser": "^0.10.0-beta.10",
"bulk-require": "1.0.1",

@@ -76,3 +76,3 @@ "cosmiconfig": "^8.0.0",

},
"gitHead": "104449aaa57c5e77625a3395897facf09f26fbed"
"gitHead": "8d081aa52e63b3cd086c61f2e3dce04961a0f0f9"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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