Socket
Socket
Sign inDemoInstall

eslint-plugin-html

Package Overview
Dependencies
Maintainers
0
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.1.1 to 8.1.2

5

CHANGELOG.md

@@ -0,1 +1,6 @@

2024-09-21 v8.1.2
- Fix sourceType config for ESLint 9
- Don't require espree directly #271
2024-04-22 v8.1.1

@@ -2,0 +7,0 @@

6

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

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

"devDependencies": {
"@html-eslint/eslint-plugin": "^0.24.1",
"@html-eslint/parser": "^0.24.1",
"@html-eslint/eslint-plugin": "^0.27.0",
"@html-eslint/parser": "^0.27.0",
"eslint": "^9.0.0",

@@ -30,0 +30,0 @@ "eslint-config-prettier": "^9.1.0",

@@ -38,12 +38,29 @@ <div align="center">

Example:
<details open>
<summary>Example with ESLint 9 and above (flat config)</summary>
```javascript
import html from "eslint-plugin-html"
export default [
{
files: ["**/*.html"],
plugins: { html },
},
]
```
</details>
<details>
<summary>Example with ESLint 8 and below</summary>
```json
{
"plugins": [
"html"
]
"plugins": ["html"]
}
```
</details>
## Disabling ESLint

@@ -95,3 +112,22 @@

<details open>
<summary>ESLint 9 and above (flat config)</summary>
```javascript
export default [
{
// ...
languageOptions: {
sourceType: "module",
},
},
]
```
</details>
<details>
<summary>ESLint 8 and below</summary>
```json
{

@@ -104,2 +140,4 @@ "parserOptions": {

</details>
To illustrate this behavior, consider this HTML extract:

@@ -148,11 +186,36 @@

<details open>
<summary>ESLint 9 and above (flat config)</summary>
```javascript
export default [
{
files: ["**/*.html", "**/*.we"],
plugins: { html },
settings: {
"html/html-extensions": [".html", ".we"], // consider .html and .we files as HTML
},
},
]
```
Note: you need to specify extensions twice, which is not ideal. This should be imporved in the
future.
</details>
<details>
<summary>ESLint 8 and below</summary>
```json
{
"plugins": [ "html" ],
"settings": {
"html/html-extensions": [".html", ".we"], // consider .html and .we files as HTML
}
"plugins": ["html"],
"settings": {
"html/html-extensions": [".html", ".we"] // consider .html and .we files as HTML
}
}
```
</details>
### `html/xml-extensions`

@@ -163,11 +226,36 @@

<details open>
<summary>ESLint 9 and above (flat config)</summary>
```javascript
export default [
{
files: ["**/*.html"],
plugins: { html },
settings: {
"html/xtml-extensions": [".html"], // consider .html files as XML
},
},
]
```
Note: you need to specify extensions twice, which is not ideal. This should be imporved in the
future.
</details>
<details>
<summary>ESLint 8 and below</summary>
```json
{
"plugins": [ "html" ],
"settings": {
"html/xml-extensions": [".html"], // consider .html files as XML
}
"plugins": ["html"],
"settings": {
"html/xml-extensions": [".html"] // consider .html files as XML
}
}
```
</details>
### `html/indent`

@@ -180,13 +268,37 @@

<details open>
<summary>ESLint 9 and above (flat config)</summary>
```javascript
export default [
{
files: ["**/*.html"],
plugins: { html },
settings: {
"html/indent": "0", // code should start at the beginning of the line (no initial indentation).
"html/indent": "+2", // indentation is the <script> indentation plus two spaces.
"html/indent": "tab", // indentation is one tab at the beginning of the line.
},
},
]
```
</details>
<details>
<summary>ESLint 8 and below</summary>
```json
{
"plugins": [ "html" ],
"settings": {
"html/indent": "0", // code should start at the beginning of the line (no initial indentation).
"html/indent": "+2", // indentation is the <script> indentation plus two spaces.
"html/indent": "tab", // indentation is one tab at the beginning of the line.
}
"plugins": ["html"],
"settings": {
"html/indent": "0", // code should start at the beginning of the line (no initial indentation).
"html/indent": "+2", // indentation is the <script> indentation plus two spaces.
"html/indent": "tab" // indentation is one tab at the beginning of the line.
}
}
```
</details>
### `html/report-bad-indent`

@@ -199,11 +311,33 @@

<details open>
<summary>ESLint 9 and above (flat config)</summary>
```javascript
export default [
{
files: ["**/*.html"],
plugins: { html },
settings: {
"html/report-bad-indent": "error",
},
},
]
```
</details>
<details>
<summary>ESLint 8 and below</summary>
```json
{
"plugins": [ "html" ],
"settings": {
"html/report-bad-indent": "error",
}
"plugins": ["html"],
"settings": {
"html/report-bad-indent": "error"
}
}
```
</details>
### `html/javascript-tag-names`

@@ -216,11 +350,33 @@

<details open>
<summary>ESLint 9 and above (flat config)</summary>
```javascript
export default [
{
files: ["**/*.html"],
plugins: { html },
settings: {
"html/javascript-tag-names": ["script", "customscript"],
},
},
]
```
</details>
<details>
<summary>ESLint 8 and below</summary>
```json
{
"plugins": [ "html" ],
"settings": {
"html/javascript-tag-names": ["script", "customscript"],
}
"plugins": ["html"],
"settings": {
"html/javascript-tag-names": ["script", "customscript"]
}
}
```
</details>
### `html/javascript-mime-types`

@@ -234,12 +390,35 @@

<details open>
<summary>ESLint 9 and above (flat config)</summary>
```javascript
export default [
{
files: ["**/*.html"],
plugins: { html },
settings: {
"html/javascript-mime-types": ["text/javascript", "text/jsx"], // also use script tags with a "text/jsx" type attribute
"html/javascript-mime-types": "/^text\\/(javascript|jsx)$/", // same thing
},
},
]
```
</details>
<details>
<summary>ESLint 8 and below</summary>
```json
{
"plugins": [ "html" ],
"settings": {
"html/javascript-mime-types": ["text/javascript", "text/jsx"], // also use script tags with a "text/jsx" type attribute
"html/javascript-mime-types": "/^text\\/(javascript|jsx)$/", // same thing
}
"plugins": ["html"],
"settings": {
"html/javascript-mime-types": ["text/javascript", "text/jsx"], // also use script tags with a "text/jsx" type attribute
"html/javascript-mime-types": "/^text\\/(javascript|jsx)$/" // same thing
}
}
```
</details>
### `html/ignore-tags-without-type`

@@ -251,11 +430,33 @@

<details open>
<summary>ESLint 9 and above (flat config)</summary>
```javascript
export default [
{
files: ["**/*.html"],
plugins: { html },
settings: {
"html/ignore-tags-without-type": true,
},
},
]
```
</details>
<details>
<summary>ESLint 8 and below</summary>
```json
{
"plugins": [ "html" ],
"settings": {
"html/ignore-tags-without-type": true,
}
"plugins": ["html"],
"settings": {
"html/ignore-tags-without-type": true
}
}
```
</details>
## Troubleshooting

@@ -262,0 +463,0 @@

@@ -32,40 +32,11 @@ "use strict"

function getLinterFromModule(moduleExports) {
return moduleExports.Linter
? moduleExports.Linter // ESLint 6+
: moduleExports // ESLint 5-
}
function getModuleFromRequire() {
return getLinterFromModule(require("eslint/lib/linter"))
}
function getModuleFromCache(key) {
if (!needles.some((needle) => key.endsWith(needle))) return
const module = require.cache[key]
if (!module || !module.exports) return
const Linter = getLinterFromModule(module.exports)
if (
typeof Linter === "function" &&
typeof Linter.prototype.verify === "function"
) {
return Linter
}
}
function iterateESLintModules(fn) {
if (!require.cache || Object.keys(require.cache).length === 0) {
// Jest is replacing the node "require" function, and "require.cache" isn't available here.
fn(getModuleFromRequire())
return
}
let found = false
for (const key in require.cache) {
const Linter = getModuleFromCache(key)
if (Linter) {
fn(Linter)
if (!needles.some((needle) => key.endsWith(needle))) continue
const module = require.cache[key]
if (module && module.exports) {
fn(module)
found = true

@@ -82,3 +53,4 @@ }

function patch(Linter) {
function patch(module) {
const Linter = getLinterFromModule(module)
// ignore if verify function is already been patched sometime before

@@ -99,3 +71,15 @@ if (Linter[LINTER_ISPATCHED_PROPERTY_NAME] === true) {

Linter.prototype._verifyWithFlatConfigArrayAndWithoutProcessors =
createVerifyWithFlatConfigPatch(verifyWithFlatConfig)
createVerifyWithFlatConfigPatch(module, verifyWithFlatConfig)
}
function getLinterFromModule(module) {
const Linter = module.exports.Linter
? module.exports.Linter // ESLint 6+
: module.exports // ESLint 5-
if (
typeof Linter === "function" &&
typeof Linter.prototype.verify === "function"
) {
return Linter
}
}

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

function createVerifyWithFlatConfigPatch(verifyWithFlatConfig) {
function createVerifyWithFlatConfigPatch(eslintModule, verifyWithFlatConfig) {
return function (textOrSourceCode, providedConfig, providedOptions) {

@@ -37,2 +37,3 @@ const callOriginalVerify = () =>

;[messages, providedConfig] = verifyExternalHtmlPlugin(
eslintModule,
providedConfig,

@@ -103,4 +104,6 @@ callOriginalVerify

const parserOptions = providedConfig.languageOptions.parserOptions || {}
if (parserOptions.sourceType === "module") {
const languageOptions = providedConfig.languageOptions || {}
const parserOptions = languageOptions.parserOptions || {}
const sourceType = languageOptions.sourceType || parserOptions.sourceType
if (sourceType === "module") {
for (const codePart of extractResult.code) {

@@ -148,3 +151,3 @@ verifyCodePart(codePart)

function verifyExternalHtmlPlugin(config, callOriginalVerify) {
function verifyExternalHtmlPlugin(eslintModule, config, callOriginalVerify) {
const htmlPluginName = findExternalHtmlPluginName(config)

@@ -168,3 +171,3 @@ if (!htmlPluginName) {

...config.languageOptions,
parser: require("espree"),
parser: eslintModule.require("espree"),
},

@@ -171,0 +174,0 @@ rules,

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