-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
Depmig/linterproviderv2
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module type="WEB_MODULE" version="4"> | ||
<component name="NewModuleRootManager" inherit-compiler-output="true"> | ||
<exclude-output /> | ||
<content url="file://$MODULE_DIR$" /> | ||
<orderEntry type="inheritedJdk" /> | ||
<orderEntry type="sourceFolder" forTests="false" /> | ||
</component> | ||
</module> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,71 @@ | ||
'use babel' | ||
|
||
var Linter = require('ember-template-lint'); | ||
var loophole = require('loophole'); | ||
var LinterHelpers = require('atom-linter'); | ||
var { File, Directory } = require('atom'); | ||
const Linter = require('ember-template-lint'); | ||
const loophole = require('loophole'); | ||
const LinterHelpers = require('atom-linter'); | ||
const {File} = require('atom'); | ||
|
||
const configFileName = ".template-lintrc.js"; | ||
|
||
function getConfigFileFromDirectory(directory) { | ||
return directory.getEntriesSync().find(function(entry) { | ||
return entry.isFile() && entry.getBaseName() === configFileName; | ||
}); | ||
return directory.getEntriesSync().find(function (entry) { | ||
return entry.isFile() && entry.getBaseName() === configFileName; | ||
}); | ||
} | ||
|
||
function findConfigFileForFilePath(editorFilePath) { | ||
let currentDir = new File(editorFilePath).getParent(); | ||
let foundConfig; | ||
while (!(foundConfig = getConfigFileFromDirectory(currentDir)) && !currentDir.isRoot()) { | ||
currentDir = currentDir.getParent(); | ||
} | ||
return foundConfig && foundConfig.getPath(); | ||
let currentDir = new File(editorFilePath).getParent(); | ||
let foundConfig; | ||
while (!(foundConfig = getConfigFileFromDirectory(currentDir)) && !currentDir.isRoot()) { | ||
currentDir = currentDir.getParent(); | ||
} | ||
return foundConfig && foundConfig.getPath(); | ||
} | ||
|
||
export function activate() { | ||
require('atom-package-deps').install('atom-ember-template-lint'); | ||
} | ||
} | ||
|
||
export function provideLinter() { | ||
return { | ||
name: 'Ember Template Linter', | ||
grammarScopes: [ | ||
'text.html.mustache', | ||
'text.html.htmlbars', | ||
'text.html.handlebars' | ||
], | ||
scope: 'file', // or 'project' | ||
lintOnFly: true, | ||
lint: function(textEditor) { | ||
return new Promise(function(resolve, reject) { | ||
let options = { | ||
configPath: findConfigFileForFilePath(textEditor.getPath()) | ||
}; | ||
let linter = new Linter(options); | ||
|
||
let linterErrors = []; | ||
return { | ||
name: 'Ember Template Linter', | ||
grammarScopes: [ | ||
'text.html.mustache', | ||
'text.html.htmlbars', | ||
'text.html.handlebars' | ||
], | ||
scope: 'file', // or 'project' | ||
lintsOnChange: true, | ||
lint: function (textEditor) { | ||
return new Promise(function (resolve, reject) { | ||
let options = { | ||
configPath: findConfigFileForFilePath(textEditor.getPath()) | ||
}; | ||
let linter = new Linter(options); | ||
|
||
loophole.allowUnsafeNewFunction(() => { | ||
linterErrors = linter.verify({ | ||
source: textEditor.getText(), | ||
moduleId: textEditor.getPath().slice(0, -4) | ||
}); | ||
}); | ||
let linterErrors = []; | ||
|
||
let errors = []; | ||
loophole.allowUnsafeNewFunction(() => { | ||
linterErrors = linter.verify({ | ||
source: textEditor.getText(), | ||
moduleId: textEditor.getPath().slice(0, -4) | ||
}); | ||
}); | ||
|
||
linterErrors.forEach((error) => { | ||
errors.push({ | ||
type: 'Error', | ||
text: error.message, | ||
range: LinterHelpers.generateRange(textEditor, error.line-1, error.column), | ||
filePath: textEditor.getPath() | ||
}); | ||
}); | ||
let errors = linterErrors.map( | ||
(error) => ({ | ||
severity: 'error', | ||
excerpt: error.message, | ||
description: error.rule, | ||
location: { | ||
file: textEditor.getPath(), | ||
position: LinterHelpers.generateRange(textEditor, error.line - 1, error.column) | ||
} | ||
}) | ||
); | ||
|
||
resolve(errors); | ||
}) | ||
} | ||
resolve(errors); | ||
}) | ||
} | ||
} | ||
} |