Skip to content
This repository was archived by the owner on Sep 5, 2022. It is now read-only.

Commit 548ac5f

Browse files
committed
total rewrite
now written i Coffeescript now supports the new atom API removing atom-keymap-plus updating atom-message-panel to 1.1.4 updating htmlhint to 0.9.6 adding support for .htmlhintrc (fixes #3)
1 parent aff23d4 commit 548ac5f

File tree

8 files changed

+91
-123
lines changed

8 files changed

+91
-123
lines changed

keymaps/htmlhint.cson

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
"atom-text-editor[data-grammar='text html basic']":
2+
"ctrl-alt-l": "htmlhint:hint"

keymaps/htmlhint.json

-8
This file was deleted.

lib/config.coffee

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
path = require("path")
2+
fs = require("fs")
3+
4+
module.exports = ->
5+
defaultConfigPath = path.normalize(path.join(process.env.HOME or process.env.HOMEPATH, ".htmlhintrc"))
6+
projectConfigPath = path.normalize(path.join(atom.project.getPath(), ".htmlhintrc"))
7+
config = {}
8+
9+
try
10+
config = JSON.parse(fs.readFileSync(defaultConfigPath, "utf-8"))
11+
catch err
12+
console.log "Error reading config file \"" + defaultConfigPath + "\": " + err if defaultConfigPath and err.code isnt "ENOENT"
13+
try
14+
config = JSON.parse(fs.readFileSync(projectConfigPath, "utf-8"))
15+
catch err
16+
console.log "Error reading config file \"" + projectConfigPath + "\": " + err if projectConfigPath and err.code isnt "ENOENT"
17+
18+
return config

lib/init.js

-44
This file was deleted.

lib/linter.coffee

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{MessagePanelView, PlainMessageView, LineMessageView} = require "atom-message-panel"
2+
config = require("./config")
3+
htmlHint = require("htmlhint").HTMLHint
4+
messages = new MessagePanelView
5+
title: "<span class=\"icon-bug\"></span> HTMLHint report"
6+
rawTitle: true
7+
closeMethod: "destroy"
8+
9+
module.exports = ->
10+
editor = atom.workspace.getActiveTextEditor()
11+
12+
return unless editor
13+
return unless editor.getGrammar().name is "HTML"
14+
15+
content = editor.getText()
16+
result = htmlHint.verify content, config()
17+
18+
messages.clear()
19+
messages.attach()
20+
21+
if atom.config.get("htmlhint.useFoldModeAsDefault") and messages.summary.css("display") is "none"
22+
messages.toggle()
23+
24+
if result.length is 0
25+
atom.config.observe "htmlhint.hideOnNoErrors", (value) ->
26+
if value is true
27+
messages.close()
28+
else
29+
messages.add new PlainMessageView
30+
message: "No errors were found!"
31+
className: "text-success"
32+
else
33+
for error in result
34+
continue if !error
35+
36+
messages.add new LineMessageView
37+
message: error.message
38+
line: error.line
39+
character: error.col
40+
preview: error.evidence.trim() if error.evidence
41+
className: "text-#{error.type}"
42+
43+
atom.workspace.onDidChangeActivePaneItem ->
44+
messages.close()

lib/linter.js

-66
This file was deleted.

lib/main.coffee

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
linter = require "./linter"
2+
module.exports =
3+
configDefaults:
4+
validateOnSave: true
5+
validateOnChange: false
6+
hideOnNoErrors: false
7+
useFoldModeAsDefault: false
8+
9+
activate: ->
10+
editor = atom.workspace.getActiveTextEditor()
11+
12+
atom.commands.add "atom-workspace", "htmlhint:hint", linter
13+
atom.config.observe "htmlhint.validateOnSave", (value) ->
14+
if value is true
15+
editor.buffer.on "saved", linter
16+
else
17+
editor.buffer.off "saved", linter
18+
19+
atom.config.observe "htmlhint.validateOnChange", (value) ->
20+
if value is true
21+
editor.buffer.on "contents-modified", linter
22+
else
23+
editor.buffer.off "contents-modified", linter

package.json

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
{
22
"name": "htmlhint",
3-
"main": "./lib/init",
3+
"main": "./lib/main",
44
"version": "0.4.0",
55
"private": true,
66
"description": "HTMLHint reports for your Atom editor",
77
"repository": "https://github.com/tcarlsen/atom-htmlhint",
88
"author": "tcarlsen",
99
"license": "MIT",
1010
"engines": {
11-
"atom": ">0.50.0"
11+
"atom": ">0.174.0"
1212
},
1313
"dependencies": {
14-
"htmlhint": "^0.9.3",
15-
"atom-message-panel": "^0.3.0",
16-
"atom-keymap-plus": "^0.1.0"
14+
"htmlhint": "^0.9.6",
15+
"atom-message-panel": "^1.1.4"
1716
}
1817
}

0 commit comments

Comments
 (0)