Skip to content

Commit

Permalink
Merge pull request #18 from grrakesh4769/depmig/linterproviderv2
Browse files Browse the repository at this point in the history
Depmig/linterproviderv2
  • Loading branch information
grrakesh4769 authored Oct 30, 2019
2 parents 81bc83e + 678fe01 commit 2df1a8a
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 50 deletions.
2 changes: 2 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions .idea/saveactions_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions atom-ember-template-lint.iml
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>
99 changes: 50 additions & 49 deletions lib/atom-ember-template-lint.js
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);
})
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"providedServices": {
"linter": {
"versions": {
"1.0.0": "provideLinter"
"2.0.0": "provideLinter"
}
}
}
Expand Down

0 comments on commit 2df1a8a

Please sign in to comment.