Skip to content

Allow adding extra grammar scopes as a configuration option #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions lib/atom-cfn-lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ module.exports = {
items: {
type: 'string'
},
description: 'Ignore Rules (space deliminated)'
description: 'Ignore Rules (space delimited)'
},
appendRules: {
title: 'Append Rules Directory',
Expand All @@ -78,13 +78,22 @@ module.exports = {
items: {
type: 'string'
},
description: 'Append Rules Directory (space deliminated)'
description: 'Append Rules Directory (space delimited)'
},
overrideSpecPath: {
title: 'Override Spec file path',
type: 'string',
description: '(Optional) Path to an override specfile json file',
default: ''
},
extraGrammarScopes: {
title: 'Extra grammar scopes',
type: 'array',
default: [],
items: {
type: 'string'
},
description: '(Optional) Allows to apply the linter to other grammar scopes than the defaults source.yaml and source.json. E.g.: source.yaml.cf (Space delimited)'
}
},
// activate linter
Expand All @@ -108,8 +117,17 @@ module.exports = {
'atom-cfn-lint.overrideSpecPath',
(value) => { this.overrideSpecPath = value }
),
atom.config.observe(
'atom-cfn-lint.extraGrammarScopes',
(value) => { this.extraGrammarScopes = value }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will only work when the package is initially loaded. You will need to handle changes in this array in the observe callback here.

Over in linter-eslint we take a slightly different approach where we set the default value of the equivalent config option to be the supported list. This does allow the user to remove supported ones, but as they are only adding them most of the time we haven't had any issues with it.

Note: Removing the contents of the Array and adding the new values isn't the most efficient, but it's super simple and when there are only a few (<10) entries in the Array it isn't exactly a performance bottleneck.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@default50 are you able to make these changes? If not I can provide some help. Thanks for pull request.

),
)

this.grammarScopes = ['source.yaml', 'source.json']
if (Array.isArray(this.extraGrammarScopes) && this.extraGrammarScopes.length) {
this.grammarScopes.push(...this.extraGrammarScopes)
}

scheduleIdleTasks()
},

Expand All @@ -122,7 +140,7 @@ module.exports = {
provideLinter() {
return {
name: 'Cfn-Lint',
grammarScopes: ['source.yaml', 'source.json'],
grammarScopes: this.grammarScopes,
scope: 'file',
lintsOnChange: false,
lint: (activeEditor) => {
Expand Down