Skip to content

Commit aa664a9

Browse files
authored
Merge pull request #7 from psbanka/supply-different-config
Adding ability to supply different config files
2 parents 9663cc2 + 081abc2 commit aa664a9

3 files changed

Lines changed: 52 additions & 7 deletions

File tree

README.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,23 @@ Then configure the rules you want to use under the rules section.
3535

3636
```json
3737
{
38-
"rules": {
39-
"hbs/rule-name": 2
40-
}
38+
"rules": {
39+
'hbs/check-hbs-template-literals': 2
40+
}
4141
}
4242
```
4343

44+
or
45+
46+
```
47+
"rules": {
48+
'hbs/check-hbs-template-literals': [
49+
'error', 2,
50+
{'ConfigFile': __dirname + '/.eslint-template-lintrc.json'}
51+
],
52+
}
53+
```
54+
4455
The plugin will report the number of errors and the first line of the first error. Here's a running example. Left-hand side is the output of `eslint` from the command-line, right-hand side is `vim` running with `eslint` (via syntastic):
4556

4657

lib/rules/check-hbs-template-literals.js

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,61 @@
44
*/
55
'use strict'
66
const TemplateLinter = require('ember-template-lint')
7-
const linter = new TemplateLinter()
7+
const fs = require('fs')
88

99
//------------------------------------------------------------------------------
1010
// Rule Definition
1111
//------------------------------------------------------------------------------
1212

1313
module.exports = {
14+
1415
meta: {
1516
docs: {
1617
description:
1718
'If you see some hbs`<h1>handlebars templates</h1>`, pass it through a linter.',
1819
category: 'Literal linting',
1920
recommended: false
2021
},
21-
fixable: null, // or "code" or "whitespace"
22+
fixable: null,
2223
schema: [
23-
// fill in your schema
24+
{
25+
oneOf: [
26+
{
27+
enum: ['tab']
28+
},
29+
{
30+
type: 'integer',
31+
minimum: 0
32+
}
33+
]
34+
},
35+
{
36+
type: 'object',
37+
properties: {
38+
'ConfigFile': {
39+
type: 'string'
40+
},
41+
},
42+
additionalProperties: false,
43+
},
2444
]
2545
},
2646

2747
create: function(context) {
48+
let config = {}
49+
let linter
50+
if (context.options.length > 1) {
51+
const extendedOptions = context.options[1]
52+
const filename = extendedOptions.ConfigFile
53+
if (filename && fs.existsSync(filename)) {
54+
config = JSON.parse(fs.readFileSync(filename))
55+
linter = new TemplateLinter({config})
56+
}
57+
}
58+
if (!linter) {
59+
linter = new TemplateLinter()
60+
}
61+
2862
//----------------------------------------------------------------------
2963
// Public
3064
//----------------------------------------------------------------------

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "eslint-plugin-hbs",
3-
"version": "0.0.5",
3+
"version": "0.1.0",
44
"description": "Provide linting for hbs template literals inside of JavaScript",
55
"keywords": [
66
"eslint",

0 commit comments

Comments
 (0)