-
Notifications
You must be signed in to change notification settings - Fork 16
Speed up and fix parsing errors #53
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,48 +1,40 @@ | ||
| path = require 'path' | ||
|
|
||
| {CompositeDisposable} = require 'atom' | ||
| {BufferedNodeProcess} = require 'atom' | ||
|
|
||
| module.exports = | ||
| config: | ||
| executablePath: | ||
| default: path.join __dirname, '..', 'node_modules', 'htmlhint', 'bin', 'htmlhint' | ||
| type: 'string' | ||
| description: 'HTMLHint Executable Path' | ||
| activate: -> | ||
| console.log 'activate linter-htmlhint' | ||
| # console.log 'config', @config | ||
| # console.log 'dirname', __dirname | ||
| @subscriptions = new CompositeDisposable | ||
| @subscriptions.add atom.config.observe 'linter-htmlhint.executablePath', | ||
| (executablePath) => | ||
| @executablePath = executablePath | ||
| @scopes = ['text.html.angular', 'text.html.basic', 'text.html.erb', 'text.html.gohtml', 'text.html.jsp', 'text.html.mustache', 'text.html.handlebars', 'text.html.ruby'] | ||
| @executablePath = path.resolve "#{__dirname}/../node_modules/htmlhint/bin/htmlhint" | ||
| @scopes = ['text.html.angular', 'text.html.basic', 'text.html.erb', 'text.html.gohtml', 'text.html.jsp', 'text.html.mustache', 'text.html.handlebars', 'text.html.ruby'] | ||
|
|
||
| deactivate: -> | ||
| @subscriptions.dispose() | ||
| @lastProcess.kill() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't be necessary. Are you seeing dead processes?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm thinking the use case for this would be when opening a really large html file and then closing the tab immediately afterwards. |
||
|
|
||
| provideLinter: -> | ||
| helpers = require('atom-linter') | ||
| provider = | ||
| grammarScopes: @scopes | ||
| scope: 'file' | ||
| lintOnFly: true | ||
| lint: (textEditor) -> | ||
| lint: (textEditor) => | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the difference between -> and => (I'm just curious about it, I'll google it later).
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This binds your function to the last parent scope so when you use |
||
| filePath = textEditor.getPath() | ||
| htmlhintrc = helpers.findFile(filePath, '.htmlhintrc') | ||
| text = textEditor.getText() | ||
| parameters = [filePath,'--format','json'] | ||
|
|
||
| if htmlhintrc and '-c' not in parameters | ||
| parameters = parameters.concat ['-c', htmlhintrc] | ||
|
|
||
| return helpers.execNode(atom.config.get('linter-htmlhint.executablePath'), parameters, {}).then (output) -> | ||
| # console.log('output', output) | ||
| linterResults = JSON.parse output | ||
| return [] unless linterResults.length | ||
| linterMessages = linterResults[0].messages | ||
| return linterMessages.map (msg) -> | ||
| range : [[msg.line-1, msg.col-1], [msg.line-1, msg.col-1]] | ||
| type : msg.type | ||
| text : msg.message | ||
| filePath : filePath | ||
| args = [filePath, '--format', 'mini'] | ||
| command = @executablePath | ||
|
|
||
| if htmlhintrc and '-c' not in args | ||
| args = args.concat ['-c', htmlhintrc] | ||
|
|
||
|
|
||
| return new Promise (resolve, reject)=> | ||
| linterMessages = [] | ||
| stdout = (data)-> | ||
| # split lines and parse json objects | ||
| data.match(/[^\r\n]+/g).forEach (d)-> | ||
| linterMessages.push JSON.parse d | ||
|
|
||
| exit = -> | ||
| resolve(linterMessages) | ||
|
|
||
| @lastProcess = new BufferedNodeProcess({command, args, stdout, exit}) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,6 @@ | |
| }, | ||
| "dependencies": { | ||
| "atom-linter": "~3.3.0", | ||
| "htmlhint": "~0.9.12" | ||
| "htmlhint": "admosity/HTMLhint#mini-format" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's not change to a different htmlhint. Add your custom changes directly to htmlhint. htmlhint moves pretty fast, I'd like to stay on the main repo. |
||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to retain the option to use a different htmlhint. This is in use by several people.