New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@html-eslint/eslint-plugin

Package Overview
Dependencies
Maintainers
1
Versions
70
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@html-eslint/eslint-plugin - npm Package Compare versions

Comparing version 0.29.0 to 0.30.0-alpha.0

101

lib/rules/indent.js

@@ -7,2 +7,6 @@ /**

* @typedef { import("../types").TagNode } TagNode
* @typedef { import("../types").RuleListener } RuleListener
* @typedef { import("eslint").AST.Token } Token
* @typedef { import("eslint").SourceCode } SourceCode
* @typedef { import("estree").TemplateLiteral } TemplateLiteral
* @typedef {Object} IndentType

@@ -15,6 +19,10 @@ * @property {"tab"} TAB

const { parse } = require("@html-eslint/template-parser");
const { RULE_CATEGORY } = require("../constants");
const { splitToLineNodes } = require("./utils/node");
const {
shouldCheckTaggedTemplateExpression,
shouldCheckTemplateLiteral,
} = require("./utils/settings");
const { getSourceCode } = require("./utils/source-code");
const { createVisitors } = require("./utils/visitors");

@@ -68,2 +76,4 @@ /** @type {MessageId} */

const sourceCode = getSourceCode(context);
let baseIndentLevel = 0;
let indentLevel = -1;

@@ -97,2 +107,5 @@ let parentIgnoringChildCount = 0;

}
function getIndentLevel() {
return indentLevel + baseIndentLevel;
}

@@ -135,3 +148,3 @@ /**

function getExpectedIndent() {
return indentChar.repeat(indentLevel);
return indentChar.repeat(getIndentLevel());
}

@@ -207,2 +220,3 @@

const expectedIndent = getExpectedIndent();
if (actualIndent.trim().length) {

@@ -216,3 +230,3 @@ return;

messageId: MESSAGE_ID.WRONG_INDENT,
data: getMessageData(actualIndent, indentLevel),
data: getMessageData(actualIndent, getIndentLevel()),
fix(fixer) {

@@ -225,3 +239,54 @@ return fixer.replaceText(targetNode, expectedIndent);

return createVisitors(context, {
/**
*
* @param {Token} token
*/
function getBaseIndentToken(token) {
/**
* @type {Token | null}
*/
let currentToken = token;
let tokenBefore = token;
while (
// @ts-ignore
(tokenBefore = sourceCode.getTokenBefore(currentToken, {
includeComments: true,
}))
) {
if (!tokenBefore) {
return currentToken;
}
if (tokenBefore.loc.start.line !== currentToken.loc.start.line) {
return currentToken;
}
currentToken = tokenBefore;
}
return tokenBefore;
}
/**
*
* @param {TemplateLiteral} node
* @returns {number}
*/
function getBaseIndentLevel(node) {
const firstToken = sourceCode.getFirstToken(node);
if (!firstToken) return 0;
const baseToken = getBaseIndentToken(firstToken);
if (!baseToken) {
return 0;
}
const spaceCount = baseToken.loc.start.column;
if (indentType === "space") {
return Math.floor(spaceCount / indentSize);
} else {
return spaceCount;
}
}
/**
* @type {RuleListener}
*/
const visitor = {
Tag(node) {

@@ -293,4 +358,30 @@ if (IGNORING_NODES.includes(node.name)) {

"CommentContent:exit": unindent,
});
};
return {
...visitor,
TaggedTemplateExpression(node) {
if (shouldCheckTaggedTemplateExpression(node, context)) {
baseIndentLevel = getBaseIndentLevel(node.quasi) + 1;
parse(node.quasi, getSourceCode(context), visitor);
}
},
"TaggedTemplateExpression:exit"(node) {
if (shouldCheckTaggedTemplateExpression(node, context)) {
baseIndentLevel = 0;
}
},
TemplateLiteral(node) {
if (shouldCheckTemplateLiteral(node, context)) {
baseIndentLevel = getBaseIndentLevel(node) + 1;
parse(node, getSourceCode(context), visitor);
}
},
"TemplateLiteral:exit"(node) {
if (shouldCheckTemplateLiteral(node, context)) {
baseIndentLevel = 0;
}
},
};
},
};

4

package.json
{
"name": "@html-eslint/eslint-plugin",
"version": "0.29.0",
"version": "0.30.0-alpha.0",
"description": "ESLint plugin for html",

@@ -58,3 +58,3 @@ "author": "yeonjuan",

},
"gitHead": "e8908db01b8bd4a682227a2144c0dd5588fc347e"
"gitHead": "bb592a93f1095534de5e0ac0c4f854cc1a49bcab"
}
declare namespace _exports {
export { RuleModule, AnyNode, LineNode, BaseNode, TagNode, IndentType, MessageId };
export { RuleModule, AnyNode, LineNode, BaseNode, TagNode, RuleListener, Token, SourceCode, TemplateLiteral, IndentType, MessageId };
}

@@ -11,2 +11,6 @@ declare const _exports: RuleModule;

type TagNode = import("../types").TagNode;
type RuleListener = import("../types").RuleListener;
type Token = import("eslint").AST.Token;
type SourceCode = import("eslint").SourceCode;
type TemplateLiteral = import("estree").TemplateLiteral;
type IndentType = {

@@ -13,0 +17,0 @@ TAB: "tab";

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