Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Fix embedded HTML scope with custom scopes #914

Merged
merged 1 commit into from
May 22, 2017
Merged
Show file tree
Hide file tree
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
21 changes: 21 additions & 0 deletions spec/linter-eslint-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -507,4 +507,25 @@ describe('The eslint provider for Linter', () => {
fs.unlinkSync(newConfigPath)
})
})

describe('works with HTML files', () => {
const embeddedScope = 'source.js.embedded.html'
const scopes = linterProvider.grammarScopes

it('adds the HTML scope when the setting is enabled', () => {
expect(scopes.includes(embeddedScope)).toBe(false)
atom.config.set('linter-eslint.lintHtmlFiles', true)
expect(scopes.includes(embeddedScope)).toBe(true)
atom.config.set('linter-eslint.lintHtmlFiles', false)
expect(scopes.includes(embeddedScope)).toBe(false)
})

it('keeps the HTML scope with custom scopes', () => {
expect(scopes.includes(embeddedScope)).toBe(false)
atom.config.set('linter-eslint.lintHtmlFiles', true)
expect(scopes.includes(embeddedScope)).toBe(true)
atom.config.set('linter-eslint.scopes', ['foo.bar'])
expect(scopes.includes(embeddedScope)).toBe(true)
})
})
})
24 changes: 15 additions & 9 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ let isConfigAtHomeRoot
// Configuration
const scopes = []
let showRule
let lintHtmlFiles
let ignoredRulesWhenModified
let ignoredRulesWhenFixing
let disableWhenNoEslintConfig
Expand Down Expand Up @@ -55,22 +56,27 @@ module.exports = {
this.subscriptions = new CompositeDisposable()
this.worker = null

const embeddedScope = 'source.js.embedded.html'
this.subscriptions.add(atom.config.observe('linter-eslint.lintHtmlFiles',
(value) => {
lintHtmlFiles = value
if (lintHtmlFiles) {
scopes.push(embeddedScope)
} else if (scopes.indexOf(embeddedScope) !== -1) {
scopes.splice(scopes.indexOf(embeddedScope), 1)
}
})
)

this.subscriptions.add(
atom.config.observe('linter-eslint.scopes', (value) => {
// Remove any old scopes
scopes.splice(0, scopes.length)
// Add the current scopes
Array.prototype.push.apply(scopes, value)
})
)

const embeddedScope = 'source.js.embedded.html'
this.subscriptions.add(atom.config.observe('linter-eslint.lintHtmlFiles',
(lintHtmlFiles) => {
if (lintHtmlFiles) {
// Ensure HTML linting still works if the setting is updated
if (lintHtmlFiles && !scopes.includes(embeddedScope)) {
scopes.push(embeddedScope)
} else if (scopes.indexOf(embeddedScope) !== -1) {
scopes.splice(scopes.indexOf(embeddedScope), 1)
}
})
)
Expand Down