Allow linter rules to define custom configuration options beyond enabled, severity, include, exclude, and only.
Use case
Rules like html-allowed-script-type need configurable options:
allowedTypes: ["text/javascript", "application/json"]
allowBlank: true/false
Example rule definition
interface HTMLAllowedScriptTypeOptions {
allowedTypes: string[]
allowBlank: boolean
}
export class HTMLAllowedScriptTypeRule extends ParserRule<HTMLAllowedScriptTypeOptions> {
name = "html-allowed-script-type"
get defaultConfig(): FullRuleConfig {
return {
enabled: true,
severity: "error"
}
}
get defaultOptions(): HTMLAllowedScriptTypeOptions {
return {
allowedTypes: ["text/javascript"],
allowBlank: true
}
}
check(result: ParseResult, context?: Partial<LintContext>): UnboundLintOffense[] {
const { allowedTypes, allowBlank } = this.options
// ...
}
}
Example config
linter:
rules:
html-allowed-script-type:
enabled: true
allowedTypes:
- text/javascript
- application/json
allowBlank: true
Related
erb_lint
| Rule |
Option |
Type |
Default |
| AllowedScriptType |
allowed_types |
String[] |
["text/javascript"] |
|
allow_blank |
boolean |
true |
|
disallow_inline_scripts |
boolean |
false |
| DeprecatedClasses |
rule_set |
RuleSet[] |
[] |
|
addendum |
String |
- |
| ErbSafety |
better_html_config |
String |
- |
| FinalNewline |
present |
boolean |
true |
| HardCodedString |
corrector |
Hash |
{} |
|
i18n_load_path |
String |
"" |
| NoJavascriptTagHelper |
correction_style |
:cdata | :plain |
:cdata |
| RightTrim |
enforced_style |
"-" | "=" |
"-" |
| Rubocop |
only |
String[] |
- |
|
rubocop_config |
Hash |
{} |
|
config_file_path |
String |
- |
| RubocopText |
only |
String[] |
- |
|
rubocop_config |
Hash |
- |
|
config_file_path |
String |
- |
| SelfClosingTag |
enforced_style |
:always | :never |
:never |
| SpaceIndentation |
tab_width |
Integer |
2 |
erblint-github
| Rule |
Option |
Type |
Default |
| AriaLabelIsWellFormatted |
exceptions |
String[] |
[] |
Allow linter rules to define custom configuration options beyond
enabled,severity,include,exclude, andonly.Use case
Rules like
html-allowed-script-typeneed configurable options:allowedTypes:["text/javascript", "application/json"]allowBlank:true/falseExample rule definition
Example config
Related
html-allowed-script-typerule #1201erb_lint
allowed_typesString[]["text/javascript"]allow_blankbooleantruedisallow_inline_scriptsbooleanfalserule_setRuleSet[][]addendumStringbetter_html_configStringpresentbooleantruecorrectorHash{}i18n_load_pathString""correction_style:cdata|:plain:cdataenforced_style"-"|"=""-"onlyString[]rubocop_configHash{}config_file_pathStringonlyString[]rubocop_configHashconfig_file_pathStringenforced_style:always|:never:nevertab_widthInteger2erblint-github
exceptionsString[][]