Skip to content
This repository was archived by the owner on Aug 7, 2023. It is now read-only.
Closed
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
54 changes: 23 additions & 31 deletions lib/init.coffee
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"
Copy link
Contributor

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.

@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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't be necessary. Are you seeing dead processes?

Copy link
Author

Choose a reason for hiding this comment

The 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) =>
Copy link
Contributor

Choose a reason for hiding this comment

The 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).

Copy link
Author

Choose a reason for hiding this comment

The 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 @ it'll be the correct one.

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})
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
},
"dependencies": {
"atom-linter": "~3.3.0",
"htmlhint": "~0.9.12"
"htmlhint": "admosity/HTMLhint#mini-format"
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

}
}
}