Using ember-template-lint executable

I want to use ember-template-lint to fix errors in my templates. According to the doc it can be installed locally inside a project: GitHub - ember-template-lint/ember-template-lint: Linter for Ember or Handlebars templates

I installed it by doing npm install --save-dev ember-template-lint and it added it to my package.json. I still cannot run ember-template-lint at the root of my project. What did I miss ?

What version of ember are you using in your project? Newer versions have ember-template-lint added automatically and have scripts in the package.json file e.g.

  "scripts": {
    "build": "ember build --environment=production",
    "lint": "npm-run-all --aggregate-output --continue-on-error --parallel \"lint:!(fix)\"",
    "lint:fix": "npm-run-all --aggregate-output --continue-on-error --parallel lint:*:fix",
    "lint:hbs": "ember-template-lint .",
    "lint:hbs:fix": "ember-template-lint . --fix",
    ...

so you can just run npm run lint:hbs in the “project context”. Alternatively you can use the path of the executable e.g. ./node_modules/... or the nicer way would be to use npx:npx ember-template-lint

Also don’t forget you’ll probably want a .template-lintrc.js in your project to specify your specific template lint config.

2 Likes

When an NPM package provides an executable, it doesn’t end up in your path automatically when you add it to a project.

Instead, you can invoke it as npm run ember-template-lint or yarn ember-template-lint.

Alternatively, you can mention ember-template-lint from inside the scripts section of package.json and invoke one of the scripts. That is how the default out-of-the-box setup works, meaning you can say npm run lint:hbs:fix or yarn lint:hbs:fix.

(This is not an ember-specific thing, this is an NPM thing.)

2 Likes

I am looking into the linter because i Migrated from 2.18 to 3.4.

Thanks for the help.