From aa36a3e88b078c6dfe41dac24add53c42428beae Mon Sep 17 00:00:00 2001 From: Erin Dachtler Date: Tue, 17 May 2016 01:50:11 -0700 Subject: [PATCH 1/6] Need tiny-promisify for changes --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index b28026b..e625d9b 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,8 @@ "dependencies": { "atom-linter": "^4.6.1", "atom-package-deps": "^4.0.1", - "htmlhint": "~0.9.12" + "htmlhint": "~0.9.12", + "tiny-promisify": "^0.1.1" }, "devDependencies": { "eslint": "^2.9.0", From 903919beb9f0b8688c57d0aeb67f1849c2dfae6e Mon Sep 17 00:00:00 2001 From: Erin Dachtler Date: Tue, 17 May 2016 01:52:17 -0700 Subject: [PATCH 2/6] Linter now directly imports htmlhint instead of running it as a subprocess. lintOnFly can be enabled as a result. No need for executable path config is there's no executable. --- lib/index.js | 64 ++++++++++++++++++++++------------------------------ 1 file changed, 27 insertions(+), 37 deletions(-) diff --git a/lib/index.js b/lib/index.js index 0f9ab45..df75025 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,8 +1,13 @@ 'use babel'; +import * as fs from 'fs'; import * as path from 'path'; -import { execNode, find, rangeFromLineNumber } from 'atom-linter'; +import { findAsync, rangeFromLineNumber } from 'atom-linter'; +import stripJsonComments from 'strip-json-comments'; +import { HTMLHint } from 'htmlhint'; +import promisify from 'tiny-promisify'; +const readFile = promisify(fs.readFile); const GRAMMAR_SCOPES = [ 'text.html.angular', 'text.html.basic', @@ -14,25 +19,26 @@ const GRAMMAR_SCOPES = [ 'text.html.ruby' ]; -export const config = { - executablePath: { - title: 'Executable Path', - description: 'HTMLHint Node Script Path', - type: 'string', - default: path.join(__dirname, '..', 'node_modules', 'htmlhint', 'bin', 'htmlhint') - } -}; - -let executablePath = ''; +export const config = {}; export function activate() { require('atom-package-deps').install('linter-htmlhint'); +} - executablePath = atom.config.get('linter-htmlhint.executablePath'); - - atom.config.observe('linter-htmlhint.executablePath', newValue => { - executablePath = newValue; - }); +function getConfig(filePath) { + return findAsync(path.dirname(filePath), '.htmlhintrc') + .then(configPath => { + if (configPath) { + return readFile(configPath, 'utf8'); + } + return null; + }) + .then(conf => { + if (conf) { + return JSON.parse(stripJsonComments(conf)); + } + return null; + }); } export function provideLinter() { @@ -40,7 +46,7 @@ export function provideLinter() { name: 'htmlhint', grammarScopes: GRAMMAR_SCOPES, scope: 'file', - lintOnFly: false, + lintOnFly: true, lint: editor => { const text = editor.getText(); const filePath = editor.getPath(); @@ -49,30 +55,14 @@ export function provideLinter() { return Promise.resolve([]); } - const parameters = [filePath, '--format', 'json']; - const htmlhintrc = find(path.dirname(filePath), '.htmlhintrc'); - - if (htmlhintrc) { - parameters.push('-c'); - parameters.push(htmlhintrc); - } - - return execNode(executablePath, parameters, {}).then(output => { - const results = JSON.parse(output); - - if (!results.length) { - return []; - } - - const messages = results[0].messages; - - return messages.map(message => ({ + return getConfig(filePath) + .then(ruleset => HTMLHint.verify(text, ruleset || undefined)) + .then(messages => messages.map(message => ({ range: rangeFromLineNumber(editor, message.line - 1, message.col - 1), type: message.type, text: message.message, filePath - })); - }); + }))); } }; } From 3989522a76cb0a2fb12433b0f776f9edd4b3e8ec Mon Sep 17 00:00:00 2001 From: Erin Dachtler Date: Tue, 17 May 2016 02:13:55 -0700 Subject: [PATCH 3/6] Froze the htmlhint dependency version. We are depending on an internal API. Incompatibilities could be introduced at any time. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e625d9b..b002ce3 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "dependencies": { "atom-linter": "^4.6.1", "atom-package-deps": "^4.0.1", - "htmlhint": "~0.9.12", + "htmlhint": "0.9.12", "tiny-promisify": "^0.1.1" }, "devDependencies": { From f84d299aac6110e87b2a9f8d968ee87a08dc308c Mon Sep 17 00:00:00 2001 From: Erin Dachtler Date: Tue, 17 May 2016 02:22:04 -0700 Subject: [PATCH 4/6] strip-json-comments is now a dependency --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index b002ce3..3c8d299 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "atom-linter": "^4.6.1", "atom-package-deps": "^4.0.1", "htmlhint": "0.9.12", + "strip-json-comments": "^2.0.1", "tiny-promisify": "^0.1.1" }, "devDependencies": { From f652f2b4c2e94cee126c68a294c54a403c9679f2 Mon Sep 17 00:00:00 2001 From: Erin Dachtler Date: Tue, 17 May 2016 21:32:19 -0700 Subject: [PATCH 5/6] Replaced all imports with targeted require calls --- lib/index.js | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/lib/index.js b/lib/index.js index df75025..16583bf 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,13 +1,5 @@ 'use babel'; -import * as fs from 'fs'; -import * as path from 'path'; -import { findAsync, rangeFromLineNumber } from 'atom-linter'; -import stripJsonComments from 'strip-json-comments'; -import { HTMLHint } from 'htmlhint'; -import promisify from 'tiny-promisify'; - -const readFile = promisify(fs.readFile); const GRAMMAR_SCOPES = [ 'text.html.angular', 'text.html.basic', @@ -26,6 +18,11 @@ export function activate() { } function getConfig(filePath) { + const fs = require('fs'); + const path = require('path'); + const readFile = require('tiny-promisify')(fs.readFile); + const { findAsync } = require('atom-linter'); + return findAsync(path.dirname(filePath), '.htmlhintrc') .then(configPath => { if (configPath) { @@ -35,7 +32,7 @@ function getConfig(filePath) { }) .then(conf => { if (conf) { - return JSON.parse(stripJsonComments(conf)); + return JSON.parse(require('strip-json-comments')(conf)); } return null; }); @@ -48,6 +45,7 @@ export function provideLinter() { scope: 'file', lintOnFly: true, lint: editor => { + const { HTMLHint } = require('htmlhint'); const text = editor.getText(); const filePath = editor.getPath(); @@ -57,12 +55,16 @@ export function provideLinter() { return getConfig(filePath) .then(ruleset => HTMLHint.verify(text, ruleset || undefined)) - .then(messages => messages.map(message => ({ - range: rangeFromLineNumber(editor, message.line - 1, message.col - 1), - type: message.type, - text: message.message, - filePath - }))); + .then(messages => { + const { rangeFromLineNumber } = require('atom-linter'); + + return messages.map(message => ({ + range: rangeFromLineNumber(editor, message.line - 1, message.col - 1), + type: message.type, + text: message.message, + filePath + })); + }); } }; } From 0755fa91d07b177ef3e3a577a890768a26bd27c5 Mon Sep 17 00:00:00 2001 From: Erin Dachtler Date: Mon, 23 May 2016 22:39:22 -0700 Subject: [PATCH 6/6] Removed unneeded config export --- lib/index.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/index.js b/lib/index.js index 16583bf..ea96090 100644 --- a/lib/index.js +++ b/lib/index.js @@ -11,8 +11,6 @@ const GRAMMAR_SCOPES = [ 'text.html.ruby' ]; -export const config = {}; - export function activate() { require('atom-package-deps').install('linter-htmlhint'); }