Skip to content

Linter: Support per-rule custom configuration options #1204

@marcoroth

Description

@marcoroth

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[] []

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions