zinyando / ember-template-lint

Linter for Ember or Handlebars templates

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ember-template-lint

npm version Build Status

ember-template-lint is a library that will lint your handlebars template and return error results.

For example, if the rule no-bare-strings is enabled, this template would be in violation:

{{!-- app/components/my-thing/template.hbs  --}}
<div>A bare string</div>

When the ember-template-lint executable is run, we would have a single result indicating that the no-bare-strings rule found an error.

Installation

This library is installed by default with new Ember apps, so check your package.json file before installing to see if you need to install it.

To install ember-template-lint

With npm:

npm install --save-dev ember-template-lint

With yarn:

yarn add ember-template-lint --dev

Node.js 10 || 12 || >=14 is required.

Usage

While ember-template-lint does have a Node API, the main way to use it is through its executable, which is intended to be installed locally within a project.

Basic usage is as straightforward as

ember-template-lint .

Workflow Examples

Basic usage with a single file

ember-template-lint "app/templates/application.hbs"

Output errors with source description

ember-template-lint "app/templates/application.hbs" --verbose

Multiple file/directory/wildcard paths are accepted

ember-template-lint "app/templates/components/**/*" "app/templates/application.hbs"

Output errors as pretty-printed JSON string

ember-template-lint "app/templates/application.hbs" --json

Ignore warnings / only report errors

ember-template-lint "app/templates/application.hbs" --quiet

Convert errors to TODOs in order to resolve at a later date

ember-template-lint . --update-todo

Number of warnings to trigger nonzero exit code

ember-template-lint "app/templates/application.hbs" --max-warnings=2

Define custom config path

Include TODOs with other output results

ember-template-lint . --include-todo

Define custom config path

ember-template-lint "app/templates/application.hbs" --config-path .my-template-lintrc.js

Read from stdin

ember-template-lint --filename app/templates/application.hbs < app/templates/application.hbs

Specify custom ignore pattern ['**/dist/**', '**/tmp/**', '**/node_modules/**'] by default

ember-template-lint "/tmp/template.hbs" --ignore-pattern "**/foo/**" --ignore-pattern "**/bar/**"

Disable ignore pattern entirely

ember-template-lint "/tmp/template.hbs" --no-ignore-pattern

Running a single rule without options

ember-template-lint --no-config-path app/templates --rule 'no-implicit-this:error'

Running a single rule with options

ember-template-lint --no-config-path app/templates --rule 'no-implicit-this:["error", { "allow": ["some-helper"] }]'

Running a single rule, disabling inline configuration

ember-template-lint --no-config-path app/templates --rule 'no-implicit-this:error' --no-inline-config

Specify a config object to use instead of what exists locally

ember-template-lint --config '{ "rules": { "no-implicit-this": { "severity": 2, "config": true } } }' test/fixtures/no-implicit-this-allow-with-regexp/app/templates

Specify a configuration to override the normally loaded config file:

ember-template-lint . --config='{"extends": "a11y"}'

Provide a custom formatter from a relative path

ember-template-lint --format ./my-shwanky-formatter.js

Provide a custom formatter from a formatter package

ember-template-lint --format ember-template-lint-formatter-snazzy

πŸ’‘ Ensure you wrap all glob patterns in quotes so that it won't be interpreted by the CLI. ember-template-lint app/templates/** (this will expand all paths in app/templates) and ember-template-lint "app/templates/**" (this will pass the glob to ember-template-lint and not interpret the glob).

For more information about the todo functionality, see the documentation.

Configuration

Project Wide

You can turn on specific rules by toggling them in a .template-lintrc.js file at the base of your project, or at a custom relative path which may be identified using the CLI:

module.exports = {
  extends: 'recommended',

  rules: {
    'no-bare-strings': true,
  },
};

For more detailed information see configuration.

Presets

Name Description
βœ… recommended enables the recommended rules
πŸ’… stylistic enables stylistic rules for those who aren't ready to adopt ember-template-lint-plugin-prettier (including stylistic rules that were previously in the recommended preset in ember-template-lint v1)

Rules

Each rule has emojis denoting:

  • what configuration it belongs to
  • πŸ”§ if some problems reported by the rule are automatically fixable by the --fix command line option
Rule ID
attribute-indentation
πŸ’… block-indentation
βœ… builtin-component-arguments
deprecated-each-syntax
βœ… deprecated-inline-view-helper
βœ… deprecated-render-helper
πŸ’… eol-last
πŸ”§ inline-link-to
πŸ’… linebreak-style
βœ… link-href-attributes
βœ…πŸ”§ link-rel-noopener
πŸ’… modifier-name-case
βœ… no-abstract-roles
βœ…πŸ”§ no-accesskey-attribute
βœ… no-action
no-action-modifiers
βœ… no-args-paths
βœ… no-arguments-for-html-elements
βœ…πŸ”§ no-aria-hidden-body
βœ… no-attrs-in-components
no-bare-strings
βœ… no-block-params-for-html-elements
no-capital-arguments
no-class-bindings
βœ…πŸ”§ no-curly-component-invocation
βœ… no-debugger
βœ… no-down-event-binding
βœ… no-duplicate-attributes
βœ… no-duplicate-id
βœ… no-duplicate-landmark-elements
no-dynamic-subexpression-invocations
no-element-event-actions
βœ… no-extra-mut-helper-argument
βœ… no-forbidden-elements
βœ… no-heading-inside-button
βœ… no-html-comments
βœ… no-implicit-this
βœ… no-index-component-invocation
βœ… no-inline-styles
βœ… no-input-block
βœ… no-input-tagname
βœ… no-invalid-block-param-definition
βœ… no-invalid-interactive
βœ… no-invalid-link-text
βœ… no-invalid-link-title
βœ… no-invalid-meta
βœ… no-invalid-role
βœ… no-link-to-positional-params
no-link-to-tagname
βœ… no-log
πŸ”§ no-model-argument-in-route-templates
πŸ’… no-multiple-empty-lines
no-mut-helper
βœ… no-negated-condition
βœ… no-nested-interactive
βœ… no-nested-landmark
βœ… no-nested-splattributes
βœ… no-obsolete-elements
βœ… no-outlet-outside-routes
βœ… no-partial
βœ… no-passed-in-event-handlers
βœ…πŸ”§ no-positional-data-test-selectors
βœ… no-positive-tabindex
βœ… no-potential-path-strings
βœ… no-quoteless-attributes
βœ…πŸ”§ no-redundant-fn
βœ…πŸ”§ no-redundant-landmark-role
no-restricted-invocations
βœ… no-shadowed-elements
πŸ”§ no-this-in-template-only-components
πŸ’… no-trailing-spaces
βœ… no-triple-curlies
βœ… no-unbalanced-curlies
βœ… no-unbound
βœ… no-unknown-arguments-for-builtin-components
βœ… no-unnecessary-component-helper
πŸ’… no-unnecessary-concat
βœ… no-unused-block-params
πŸ’… no-whitespace-for-layout
πŸ’… no-whitespace-within-word
βœ… no-yield-only
no-yield-to-default
πŸ’… quotes
βœ…πŸ”§ require-button-type
require-each-key
require-form-method
βœ…πŸ”§ require-has-block-helper
βœ… require-iframe-title
βœ… require-input-label
βœ… require-lang-attribute
require-splattributes
βœ… require-valid-alt-text
πŸ’… self-closing-void-elements
βœ… simple-unless
βœ… splat-attributes-only
βœ… style-concatenation
βœ… table-groups
template-length

Supporting the --fix option

You can add a fixer to a rule. See fixer documentation for more details.

Sharing configs

It is possible to share a config (extends) or plugin (custom rules) across projects. See ember-template-lint-plugin-peopleconnect for an example.

Defining your own rules

You can define and use your own custom rules using the plugin system. See plugin documentation for more details.

Semantic Versioning Policy

The semver policy for this addon can be read here: semver policy.

Contributing

See the Contributing Guidelines for information on how to help out.

License

This project is licensed under the MIT License.

About

Linter for Ember or Handlebars templates

License:MIT License


Languages

Language:JavaScript 99.9%Language:EJS 0.1%