From 406e5db35215c74a025159d4ffdffaffc535be93 Mon Sep 17 00:00:00 2001 From: Kabbaj Amine Date: Mon, 3 Oct 2016 21:02:21 +0300 Subject: [PATCH 1/2] Add sass/scss support with sass-lint --- README.md | 1 + ale_linters/sass/sassLint.vim | 14 ++++++++++++++ ale_linters/scss/sassLint.vim | 14 ++++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 ale_linters/sass/sassLint.vim create mode 100644 ale_linters/scss/sassLint.vim diff --git a/README.md b/README.md index 5b9ceb3..3a6b258 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,7 @@ name. That seems to be the fairest way to arrange this table. | JavaScript | [eslint](http://eslint.org/), [jscs](http://jscs.info/), [jshint](http://jshint.com/) | | Python | [flake8](http://flake8.pycqa.org/en/latest/) | | Ruby | [rubocop](https://github.com/bbatsov/rubocop) | +| SASS/SCSS | [sass-lint](https://www.npmjs.com/package/sass-lint) | | TypeScript | [tslint](https://github.com/palantir/tslint)^ | | Vim | [vint](https://github.com/Kuniwak/vint)^ | diff --git a/ale_linters/sass/sassLint.vim b/ale_linters/sass/sassLint.vim new file mode 100644 index 0000000..fee5016 --- /dev/null +++ b/ale_linters/sass/sassLint.vim @@ -0,0 +1,14 @@ +" Author: KabbAmine - https://github.com/KabbAmine + +if exists('g:loaded_ale_linters_sass_sassLint') + finish +endif + +let g:loaded_ale_linters_sass_sassLint = 1 + +call ALEAddLinter('sass', { +\ 'name': 'sassLint', +\ 'executable': 'sass-lint', +\ 'command': g:ale#util#stdin_wrapper . ' .sass sass-lint -v -q -f compact', +\ 'callback': 'ale_linters#css#csslint#Handle', +\}) diff --git a/ale_linters/scss/sassLint.vim b/ale_linters/scss/sassLint.vim new file mode 100644 index 0000000..b49728f --- /dev/null +++ b/ale_linters/scss/sassLint.vim @@ -0,0 +1,14 @@ +" Author: KabbAmine - https://github.com/KabbAmine + +if exists('g:loaded_ale_linters_scss_sassLint') + finish +endif + +let g:loaded_ale_linters_scss_sassLint = 1 + +call ALEAddLinter('scss', { +\ 'name': 'sassLint', +\ 'executable': 'sass-lint', +\ 'command': g:ale#util#stdin_wrapper . ' .scss sass-lint -v -q -f compact', +\ 'callback': 'ale_linters#css#csslint#Handle', +\}) From 65f5e15af5d672aec3f538ebd7ce9f2c7bac7e9f Mon Sep 17 00:00:00 2001 From: w0rp Date: Mon, 3 Oct 2016 23:24:18 +0100 Subject: [PATCH 2/2] Rename the SASS files to follow the convention from other files, and move the function for handling CSSLint style output into the handlers file. --- ale_linters/css/csslint.vim | 49 +------------------ .../sass/{sassLint.vim => sasslint.vim} | 6 +-- .../scss/{sassLint.vim => sasslint.vim} | 6 +-- plugin/ale/handlers.vim | 47 ++++++++++++++++++ 4 files changed, 54 insertions(+), 54 deletions(-) rename ale_linters/sass/{sassLint.vim => sasslint.vim} (62%) rename ale_linters/scss/{sassLint.vim => sasslint.vim} (62%) diff --git a/ale_linters/css/csslint.vim b/ale_linters/css/csslint.vim index f9f6ed3..e212aec 100644 --- a/ale_linters/css/csslint.vim +++ b/ale_linters/css/csslint.vim @@ -7,56 +7,9 @@ endif let g:loaded_ale_linters_css_csslint = 1 -function! ale_linters#css#csslint#Handle(buffer, lines) - " Matches patterns line the following: - " - " something.css: line 2, col 1, Error - Expected RBRACE at line 2, col 1. (errors) - " something.css: line 2, col 5, Warning - Expected (inline | block | list-item | inline-block | table | inline-table | table-row-group | table-header-group | table-footer-group | table-row | table-column-group | table-column | table-cell | table-caption | grid | inline-grid | run-in | ruby | ruby-base | ruby-text | ruby-base-container | ruby-text-container | contents | none | -moz-box | -moz-inline-block | -moz-inline-box | -moz-inline-grid | -moz-inline-stack | -moz-inline-table | -moz-grid | -moz-grid-group | -moz-grid-line | -moz-groupbox | -moz-deck | -moz-popup | -moz-stack | -moz-marker | -webkit-box | -webkit-inline-box | -ms-flexbox | -ms-inline-flexbox | flex | -webkit-flex | inline-flex | -webkit-inline-flex) but found 'wat'. (known-properties) - " - " These errors can be very massive, so the type will be moved to the front - " so you can actually read the error type. - let pattern = '^.*: line \(\d\+\), col \(\d\+\), \(Error\|Warning\) - \(.\+\) (\([^)]\+\))$' - let output = [] - " Some errors have line numbers beyond the end of the file, - " so we need to adjust them so they set the error at the last line - " of the file instead. - " - " TODO: Find a faster way to compute this. - let last_line_number = len(getbufline(a:buffer, 1, '$')) - - for line in a:lines - let l:match = matchlist(line, pattern) - - if len(l:match) == 0 - continue - endif - - let text = l:match[4] - let type = l:match[3] - let errorGroup = l:match[5] - - " Put the error group at the front, so we can see what kind of error - " it is on small echo lines. - let text = '(' . errorGroup . ') ' . text - - " vcol is Needed to indicate that the column is a character. - call add(output, { - \ 'bufnr': a:buffer, - \ 'lnum': min([l:match[1] + 0, last_line_number]), - \ 'vcol': 0, - \ 'col': l:match[2] + 0, - \ 'text': text, - \ 'type': type ==# 'Warning' ? 'W' : 'E', - \ 'nr': -1, - \}) - endfor - - return output -endfunction - call ALEAddLinter('css', { \ 'name': 'csslint', \ 'executable': 'csslint', \ 'command': g:ale#util#stdin_wrapper . ' .css csslint --format=compact', -\ 'callback': 'ale_linters#css#csslint#Handle', +\ 'callback': 'ale#handlers#HandleCSSLintFormat', \}) diff --git a/ale_linters/sass/sassLint.vim b/ale_linters/sass/sasslint.vim similarity index 62% rename from ale_linters/sass/sassLint.vim rename to ale_linters/sass/sasslint.vim index fee5016..278ba99 100644 --- a/ale_linters/sass/sassLint.vim +++ b/ale_linters/sass/sasslint.vim @@ -1,14 +1,14 @@ " Author: KabbAmine - https://github.com/KabbAmine -if exists('g:loaded_ale_linters_sass_sassLint') +if exists('g:loaded_ale_linters_sass_sasslint') finish endif -let g:loaded_ale_linters_sass_sassLint = 1 +let g:loaded_ale_linters_sass_sasslint = 1 call ALEAddLinter('sass', { \ 'name': 'sassLint', \ 'executable': 'sass-lint', \ 'command': g:ale#util#stdin_wrapper . ' .sass sass-lint -v -q -f compact', -\ 'callback': 'ale_linters#css#csslint#Handle', +\ 'callback': 'ale#handlers#HandleCSSLintFormat', \}) diff --git a/ale_linters/scss/sassLint.vim b/ale_linters/scss/sasslint.vim similarity index 62% rename from ale_linters/scss/sassLint.vim rename to ale_linters/scss/sasslint.vim index b49728f..a02f7ee 100644 --- a/ale_linters/scss/sassLint.vim +++ b/ale_linters/scss/sasslint.vim @@ -1,14 +1,14 @@ " Author: KabbAmine - https://github.com/KabbAmine -if exists('g:loaded_ale_linters_scss_sassLint') +if exists('g:loaded_ale_linters_scss_sasslint') finish endif -let g:loaded_ale_linters_scss_sassLint = 1 +let g:loaded_ale_linters_scss_sasslint = 1 call ALEAddLinter('scss', { \ 'name': 'sassLint', \ 'executable': 'sass-lint', \ 'command': g:ale#util#stdin_wrapper . ' .scss sass-lint -v -q -f compact', -\ 'callback': 'ale_linters#css#csslint#Handle', +\ 'callback': 'ale#handlers#HandleCSSLintFormat', \}) diff --git a/plugin/ale/handlers.vim b/plugin/ale/handlers.vim index 6777ac4..afdb67a 100644 --- a/plugin/ale/handlers.vim +++ b/plugin/ale/handlers.vim @@ -38,3 +38,50 @@ function! ale#handlers#HandleGCCFormat(buffer, lines) return output endfunction + +function! ale#handlers#HandleCSSLintFormat(buffer, lines) + " Matches patterns line the following: + " + " something.css: line 2, col 1, Error - Expected RBRACE at line 2, col 1. (errors) + " something.css: line 2, col 5, Warning - Expected (inline | block | list-item | inline-block | table | inline-table | table-row-group | table-header-group | table-footer-group | table-row | table-column-group | table-column | table-cell | table-caption | grid | inline-grid | run-in | ruby | ruby-base | ruby-text | ruby-base-container | ruby-text-container | contents | none | -moz-box | -moz-inline-block | -moz-inline-box | -moz-inline-grid | -moz-inline-stack | -moz-inline-table | -moz-grid | -moz-grid-group | -moz-grid-line | -moz-groupbox | -moz-deck | -moz-popup | -moz-stack | -moz-marker | -webkit-box | -webkit-inline-box | -ms-flexbox | -ms-inline-flexbox | flex | -webkit-flex | inline-flex | -webkit-inline-flex) but found 'wat'. (known-properties) + " + " These errors can be very massive, so the type will be moved to the front + " so you can actually read the error type. + let pattern = '^.*: line \(\d\+\), col \(\d\+\), \(Error\|Warning\) - \(.\+\) (\([^)]\+\))$' + let output = [] + " Some errors have line numbers beyond the end of the file, + " so we need to adjust them so they set the error at the last line + " of the file instead. + " + " TODO: Find a faster way to compute this. + let last_line_number = len(getbufline(a:buffer, 1, '$')) + + for line in a:lines + let l:match = matchlist(line, pattern) + + if len(l:match) == 0 + continue + endif + + let text = l:match[4] + let type = l:match[3] + let errorGroup = l:match[5] + + " Put the error group at the front, so we can see what kind of error + " it is on small echo lines. + let text = '(' . errorGroup . ') ' . text + + " vcol is Needed to indicate that the column is a character. + call add(output, { + \ 'bufnr': a:buffer, + \ 'lnum': min([l:match[1] + 0, last_line_number]), + \ 'vcol': 0, + \ 'col': l:match[2] + 0, + \ 'text': text, + \ 'type': type ==# 'Warning' ? 'W' : 'E', + \ 'nr': -1, + \}) + endfor + + return output +endfunction