Skip to content

Commit

Permalink
feat: support html/ignore-tags-without-type to ignore linting tags …
Browse files Browse the repository at this point in the history
…without specifying types
  • Loading branch information
aleen42 authored and BenoitZugmeyer committed Apr 8, 2024
1 parent 73e2e2c commit 3efdc44
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- [`html/report-bad-indent`](#htmlreport-bad-indent)
- [`html/javascript-tag-names`](#htmljavascript-tag-names)
- [`html/javascript-mime-types`](#htmljavascript-mime-types)
- [`html/ignore-tags-without-type`](#htmlignore-tags-without-type)
- [Troubleshooting](#troubleshooting)
- [No file linted when running `eslint` on a directory](#no-file-linted-when-running-eslint-on-a-directory)
- [Linting templates (or PHP)](#linting-templates-or-php)
Expand Down Expand Up @@ -232,6 +233,20 @@ If a MIME type starts with a `/`, it will be considered as a regular expression.
}
```

### `html/ignore-tags-without-type`

By default, the plugin lints `<script>` tags which has not specified types. If you want to ignore it
you can ignore it. Example:

```javascript
{
"plugins": [ "html" ],
"settings": {
"html/ignore-tags-without-type": true,
}
}
```

## Troubleshooting

### No file linted when running `eslint` on a directory
Expand Down
3 changes: 2 additions & 1 deletion src/extract.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function iterateScripts(code, options, onChunk) {
const xmlMode = options.xmlMode
const isJavaScriptMIMEType = options.isJavaScriptMIMEType || (() => true)
const javaScriptTagNames = options.javaScriptTagNames || ["script"]
const ignoreTagsWithoutType = options.ignoreTagsWithoutType || false;
let index = 0
let inScript = false
let cdata = []
Expand All @@ -33,7 +34,7 @@ function iterateScripts(code, options, onChunk) {
return
}

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

Expand Down
3 changes: 3 additions & 0 deletions src/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ function getSettings(settings) {
"script",
]

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

let reportBadIndent
switch (getSetting(settings, "report-bad-indent")) {
case undefined:
Expand Down Expand Up @@ -110,6 +112,7 @@ function getSettings(settings) {
indent,
reportBadIndent,
isJavaScriptMIMEType,
ignoreTagsWithoutType,
}
}

Expand Down

0 comments on commit 3efdc44

Please sign in to comment.