Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Commit

Permalink
Use JSON scss-lint formatter, add additionalArguments option
Browse files Browse the repository at this point in the history
  • Loading branch information
caseywebdev committed May 29, 2015
1 parent 42c672b commit 1a18cf0
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 42 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
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
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,15 @@ $ apm install linter-scss-lint

## Settings
You can configure linter-scss-lint by editing ~/.atom/config.cson (choose Open Your Config in Atom menu):
```
```cson
'linter-scss-lint':
'executablePath': null #scss-lint path. run 'which scss-lint' to find the path
'excludedLinters': [] # a list of linters to exclude from running. run 'scss-lint --show-linters' to see a list of linters that can be excluded.

# Optionally specify additional arguments to be passed to `scss-lint`.
# Run `scss-lint -h` to see available options.
'additionalArguments': null

# The `scss-lint` path. Run `which scss-lint` to find this path.
'executablePath': null
```

## Config file
Expand Down
13 changes: 5 additions & 8 deletions lib/init.coffee
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'
62 changes: 32 additions & 30 deletions lib/linter-scss-lint.coffee
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

0 comments on commit 1a18cf0

Please sign in to comment.