This repository has been archived by the owner on Aug 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use JSON scss-lint formatter, add additionalArguments option
- Loading branch information
1 parent
42c672b
commit 1a18cf0
Showing
4 changed files
with
51 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
## master | ||
* use the JSON scss-lint formatter for better error reporting and scss-lint >= | ||
0.39.0 support | ||
* remove `excludedLinters` option in favor of `additionalArguments` option | ||
|
||
## 0.0.13 | ||
* expose executablePath in settings-view | ||
|
||
## 0.0.12 | ||
* Parse HTML entity characters in output [#19](https://github.com/AtomLinter/linter-scss-lint/pull/19) | ||
|
||
## 0.0.9 | ||
* Add support for the .scss-lint.yml config file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,13 @@ | ||
module.exports = | ||
config: | ||
additionalArguments: | ||
title: 'Additional Arguments' | ||
type: 'string' | ||
default: '' | ||
executablePath: | ||
title: 'Scss-lint Executable Path' | ||
description: 'The path where scss-lint is located.' | ||
title: 'Executable Path' | ||
type: 'string' | ||
default: '' | ||
excludedLinters: | ||
description: 'A list of linters to exclude from running. run `scss-lint --show-linters` to see a list of linters that can be excluded.' | ||
type: 'array' | ||
default: [] | ||
items: | ||
type: 'string' | ||
|
||
activate: -> | ||
console.log 'activate linter-scss-lint' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,46 @@ | ||
linterPath = atom.packages.getLoadedPackage("linter").path | ||
Linter = require "#{linterPath}/lib/linter" | ||
findFile = require "#{linterPath}/lib/util" | ||
|
||
{findFile} = require "#{linterPath}/lib/utils" | ||
{Range} = require 'atom' | ||
|
||
class LinterScssLint extends Linter | ||
# The syntax that the linter handles. May be a string or | ||
# list/tuple of strings. Names should be all lowercase. | ||
@syntax: 'source.css.scss' | ||
|
||
linterName: 'scss-lint' | ||
|
||
options: ['excludedLinters', 'executablePath'] | ||
|
||
# A regex pattern used to extract information from the executable's output. | ||
regex: 'line="(?<line>\\d+)" column="(?<col>\\d+)" .*? severity="((?<error>error)|(?<warning>warning))" reason="(?<message>.*?)"' | ||
|
||
updateOption: (option) => | ||
super(option) | ||
cmd: 'scss-lint --format JSON' | ||
|
||
# build cmd | ||
@cmd = 'scss-lint --format=XML' | ||
@cmd += " --exclude-linter=#{@excludedLinters.toString()}" if @excludedLinters and @excludedLinters.length > 0 | ||
options: ['additionalArguments', 'executablePath'] | ||
|
||
config = findFile @cwd, ['.scss-lint.yml'] | ||
if config | ||
@cmd += " -c #{config}" | ||
|
||
formatMessage: (match) -> | ||
map = { | ||
quot: '"' | ||
amp: '&' | ||
lt: '<' | ||
gt: '>' | ||
beforeSpawnProcess: (command, args, options) -> | ||
{additionalArguments} = options | ||
{ | ||
command, | ||
args: args.slice(0, -1).concat( | ||
if config = findFile @cwd, '.scss-lint.yml' then ['-c', config] else [] | ||
if additionalArguments then additionalArguments.split(' ') else [] | ||
args.slice(-1) | ||
) | ||
options | ||
} | ||
|
||
message = match.message | ||
for key,value of map | ||
regex = new RegExp '&' + key + ';', 'g' | ||
message = message.replace(regex, value) | ||
|
||
return message | ||
processMessage: (message, cb) -> | ||
try | ||
files = JSON.parse(message) || {} | ||
catch | ||
return cb [@createMessage {reason: message}] | ||
|
||
cb(@createMessage lint for lint in files[Object.keys(files)[0]] || []) | ||
|
||
createMessage: (lint) -> | ||
{ | ||
line: line = (lint.line || 1) - 1, | ||
col: col = (lint.column || 1) - 1, | ||
level: lint.severity || 'error', | ||
message: (lint.reason || 'Unknown Error') + | ||
(if lint.linter then " (#{lint.linter})" else ''), | ||
linter: @linterName, | ||
range: new Range([line, col], [line, col + (lint.length || 0)]) | ||
} | ||
|
||
module.exports = LinterScssLint |