Socket
Socket
Sign inDemoInstall

eslint-plugin-html

Package Overview
Dependencies
Maintainers
1
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-html - npm Package Compare versions

Comparing version 8.0.0 to 8.1.0

src/pluginReference.js

7

CHANGELOG.md

@@ -0,1 +1,8 @@

2024-04-10 v8.1.0
- Introduce the `html/ignore-tags-without-type` setting #249
- Fix files with unknown extensions being considered as XML #257
- Fix plugin applied even if it's not in the configuration #263
- Update dependencies
2024-02-09 v8.0.0

@@ -2,0 +9,0 @@

8

package.json
{
"name": "eslint-plugin-html",
"version": "8.0.0",
"version": "8.1.0",
"description": "A ESLint plugin to lint and fix inline scripts contained in HTML files.",

@@ -26,5 +26,5 @@ "license": "ISC",

"devDependencies": {
"@html-eslint/eslint-plugin": "^0.23.1",
"@html-eslint/parser": "^0.23.0",
"eslint": "^8.56.0",
"@html-eslint/eslint-plugin": "^0.24.1",
"@html-eslint/parser": "^0.24.1",
"eslint": "^9.0.0",
"eslint-config-prettier": "^9.1.0",

@@ -31,0 +31,0 @@ "jest": "^29.7.0",

<div align="center">
<img src="media/logo.svg" width="150" height="150">
<h1>eslint-plugin-html</h1>
<a href="https://www.npmjs.com/package/eslint-plugin-html"><img alt="NPM version" src="https://img.shields.io/npm/v/eslint-plugin-html.svg"></a>
<a href="https://github.com/BenoitZugmeyer/eslint-plugin-html/actions?query=workflow%3ATests"><img alt="Tests Status" src="https://img.shields.io/github/workflow/status/BenoitZugmeyer/eslint-plugin-html/Tests"></a>
<a href="https://www.npmjs.com/package/eslint-plugin-html"><img alt="NPM version" src="https://img.shields.io/npm/v/eslint-plugin-html"></a>
<a href="https://github.com/BenoitZugmeyer/eslint-plugin-html/actions/workflows/tests.yml"><img alt="Tests Status" src="https://img.shields.io/github/actions/workflow/status/BenoitZugmeyer/eslint-plugin-html/tests.yml"></a>
<p>A <a href="http://eslint.org">ESLint</a> plugin to lint and fix inline scripts contained in HTML files.</p>

@@ -22,2 +22,3 @@ </div>

- [`html/javascript-mime-types`](#htmljavascript-mime-types)
- [`html/ignore-tags-without-type`](#htmlignore-tags-without-type)
- [Troubleshooting](#troubleshooting)

@@ -236,2 +237,17 @@ - [No file linted when running `eslint` on a directory](#no-file-linted-when-running-eslint-on-a-directory)

### `html/ignore-tags-without-type`
By default, the code between `<script>` tags is considered JavaScript if there is no `type`
attribute. You can set this setting to `true` to ignore script tags without a `type` attribute.
Example:
```javascript
{
"plugins": [ "html" ],
"settings": {
"html/ignore-tags-without-type": true,
}
}
```
## Troubleshooting

@@ -238,0 +254,0 @@

@@ -10,8 +10,8 @@ "use strict"

function iterateScripts(code, options, onChunk) {
function iterateScripts(code, xmlMode, options, onChunk) {
if (!code) return
const xmlMode = options.xmlMode
const isJavaScriptMIMEType = options.isJavaScriptMIMEType || (() => true)
const javaScriptTagNames = options.javaScriptTagNames || ["script"]
const ignoreTagsWithoutType = options.ignoreTagsWithoutType || false
let index = 0

@@ -37,3 +37,7 @@ let inScript = false

if (attrs.type && !isJavaScriptMIMEType(attrs.type)) {
if (attrs.type) {
if (!isJavaScriptMIMEType(attrs.type)) {
return
}
} else if (ignoreTagsWithoutType) {
return

@@ -210,9 +214,3 @@ }

function extract(
code,
indentDescriptor,
xmlMode,
javaScriptTagNames,
isJavaScriptMIMEType
) {
function extract(code, xmlMode, options) {
const badIndentationLines = []

@@ -223,41 +221,37 @@ const codeParts = []

iterateScripts(
code,
{ xmlMode, javaScriptTagNames, isJavaScriptMIMEType },
(chunk) => {
const slice = code.slice(chunk.start, chunk.end)
if (chunk.type === "html") {
const match = slice.match(/\r\n|\n|\r/g)
if (match) lineNumber += match.length
previousHTML = slice
} else if (chunk.type === "script") {
const transformedCode = new TransformableString(code)
let indentSlice = slice
for (const cdata of chunk.cdata) {
transformedCode.replace(cdata.start, cdata.end, "")
if (cdata.end === chunk.end) {
indentSlice = code.slice(chunk.start, cdata.start)
}
iterateScripts(code, xmlMode, options, (chunk) => {
const slice = code.slice(chunk.start, chunk.end)
if (chunk.type === "html") {
const match = slice.match(/\r\n|\n|\r/g)
if (match) lineNumber += match.length
previousHTML = slice
} else if (chunk.type === "script") {
const transformedCode = new TransformableString(code)
let indentSlice = slice
for (const cdata of chunk.cdata) {
transformedCode.replace(cdata.start, cdata.end, "")
if (cdata.end === chunk.end) {
indentSlice = code.slice(chunk.start, cdata.start)
}
transformedCode.replace(0, chunk.start, "")
transformedCode.replace(chunk.end, code.length, "")
for (const action of dedent(
computeIndent(indentDescriptor, previousHTML, indentSlice),
indentSlice
)) {
lineNumber += 1
if (action.type === "dedent") {
transformedCode.replace(
chunk.start + action.from,
chunk.start + action.to,
""
)
} else if (action.type === "bad-indent") {
badIndentationLines.push(lineNumber)
}
}
transformedCode.replace(0, chunk.start, "")
transformedCode.replace(chunk.end, code.length, "")
for (const action of dedent(
computeIndent(options.indent, previousHTML, indentSlice),
indentSlice
)) {
lineNumber += 1
if (action.type === "dedent") {
transformedCode.replace(
chunk.start + action.from,
chunk.start + action.to,
""
)
} else if (action.type === "bad-indent") {
badIndentationLines.push(lineNumber)
}
codeParts.push(transformedCode)
}
codeParts.push(transformedCode)
}
)
})

@@ -264,0 +258,0 @@ return {

@@ -8,3 +8,6 @@ "use strict"

} = require("./verifyWithFlatConfigPatch")
const pluginReference = require("./pluginReference")
module.exports = pluginReference
const LINTER_ISPATCHED_PROPERTY_NAME =

@@ -76,3 +79,3 @@ "__eslint-plugin-html-verify-function-is-patched"

eslintPath = require.resolve("eslint")
} catch (e) {
} catch {
eslintPath = "(not found)"

@@ -82,3 +85,3 @@ }

eslintVersion = require("eslint/package.json").version
} catch (e) {
} catch {
eslintVersion = "n/a"

@@ -85,0 +88,0 @@ }

@@ -57,2 +57,5 @@ "use strict"

const ignoreTagsWithoutType =
getSetting(settings, "ignore-tags-without-type") || false
let reportBadIndent

@@ -114,2 +117,3 @@ switch (getSetting(settings, "report-bad-indent")) {

isJavaScriptMIMEType,
ignoreTagsWithoutType,
}

@@ -116,0 +120,0 @@ }

@@ -46,6 +46,4 @@ const getSettings = require("./settings").getSettings

textOrSourceCode,
pluginSettings.indent,
mode === "xml",
pluginSettings.javaScriptTagNames,
pluginSettings.isJavaScriptMIMEType
pluginSettings
)

@@ -52,0 +50,0 @@

@@ -6,2 +6,3 @@ const getSettings = require("./settings").getSettings

const { remapMessages } = require("./remapMessages")
const pluginReference = require("./pluginReference")

@@ -23,5 +24,13 @@ const PREPARE_RULE_NAME = "__eslint-plugin-html-prepare"

if (!Object.values(providedConfig.plugins).includes(pluginReference)) {
return callOriginalVerify()
}
const pluginSettings = getSettings(providedConfig.settings || {})
const mode = getFileMode(pluginSettings, providedOptions.filename)
if (!mode) {
return callOriginalVerify()
}
let messages

@@ -35,6 +44,4 @@ ;[messages, providedConfig] = verifyExternalHtmlPlugin(

textOrSourceCode,
pluginSettings.indent,
mode === "xml",
pluginSettings.javaScriptTagNames,
pluginSettings.isJavaScriptMIMEType
pluginSettings
)

@@ -119,3 +126,3 @@

return require(name)
} catch (e) {
} catch {
return undefined

@@ -122,0 +129,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