https://github.com/sanand0/eslint-plugin-template
Parses out template declarations found in js and html files.
https://github.com/sanand0/eslint-plugin-template
library tool
Last synced: 11 months ago
JSON representation
Parses out template declarations found in js and html files.
- Host: GitHub
- URL: https://github.com/sanand0/eslint-plugin-template
- Owner: sanand0
- License: mit
- Created: 2016-09-12T05:20:11.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2024-12-25T11:54:34.000Z (over 1 year ago)
- Last Synced: 2025-07-31T13:38:59.055Z (11 months ago)
- Topics: library, tool
- Language: JavaScript
- Size: 158 KB
- Stars: 5
- Watchers: 3
- Forks: 3
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# eslint-plugin-template
Parses out template declarations found in js and html files.
For example if you have a file like below, eslint will not be able to parse it
normally due to the template markers. With this plugin, the linter is able to
work normally. Note that whatever is inside the markers is replaced with `{}`.
```js
{# Set data in the JS variable data #} // ignored
{% import json %} // ignored
var x = {{ json.dumps(data) }} // becomes var x = {}
var y = {% raw json.dumps(data) %} // becomes var y = {}
```
It handles conditional templates within JavaScript similarly.
```js
{% if true %}
var x = 1
{% else %}
var x = 2
{% endif %}
```
becomes:
```js
var x = 1
var x = 2
```
If there are edge cases that still cannot be handled, wrap them inside `/* eslint-disable */` and `/* eslint-enable */`:
```js
foo({{x}})
/* eslint-disable */
var x = {% if x %}{{x}}{% else %}0{% endif %}
/* eslint-enable */
```
becomes:
```js
foo({})
```
## Installation
```bash
npm install --save-dev eslint eslint-plugin-template
```
## Usage
Add `template` to the plugins section of your `.eslintrc` configuration file:
```json
{
"plugins": [
"template"
]
}
```
## Tests
```bash
npm test
```
## Release
- Update the version in `package.json`
- Commit to the master branch, update the tag, and push
- Run `npm publish`