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

Commit 7c83a0b

Browse files
committed
Merge pull request #93 from AtomLinter/feature/support-syntaxes
Add helper tests constants and support extra syntaxes
2 parents b379bea + 2bc61b6 commit 7c83a0b

File tree

6 files changed

+98
-6
lines changed

6 files changed

+98
-6
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 1.5.0
2+
- Allows the inclusion of files with extra extensions such as 'file.scss.liquid'
3+
- Updated to Atom linter ^5.0.1
4+
- Includes eslint updates for development
5+
16
## 1.4.3
27
- Force latest version of sass-lint 1.7.0
38
- Update a few dependencies

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ There are three options you can configure either within the plugin or by editing
4646

4747
* `globalSassLint` This allows you to specify that you want to use your globally installed version of `sass-lint` (`npm install -g sass-lint`) instead of the version bundled with `linter-sass-lint`.
4848

49+
### Extra File Extensions
50+
51+
This plugin will attempt to lint a file with framework specific file extensions on top of the usual `.scss` and `.sass` extensions such as with shopify's `.scss.liquid` extension as long as you still include `.scss` or `.sass` somewhere in the file, you must also ensure that the Atom grammar scope for that file is set to either SCSS or Sass depending on which it corresponds to.
52+
53+
This does not mean that sass-lint will be able to definitely parse any sort of non standard SCSS or Sass code and if you use any platform specific code in the file it will almost definitely produce a parse error. Sass-lint will not be moving to support any use of non standard language outside of the Sass spec.
54+
55+
4956
### Contributing
5057

5158
Contributions, suggestions and fixes are more than welcome.

lib/constants.coffee

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports =
2+
SASSLINT_DOC_URL: 'https://github.com/sasstools/sass-lint/tree/master/docs/rules',
3+
VALID_SYNTAXES: ['scss', 'sass']

lib/helpers.coffee

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,35 @@
1+
path = require 'path'
2+
{SASSLINT_DOC_URL, VALID_SYNTAXES} = require './constants.coffee'
3+
14
module.exports =
25

3-
# Constructs the rule URI from the rule ID provided
6+
###*
7+
* Function to construct the rule URI from the rule ID provided
8+
* @param {string} ruleId - The rule name / id
9+
* @return {string} The rule URL
10+
###
411
getRuleURI: (ruleId) ->
5-
sassLintDocs = 'https://github.com/sasstools/sass-lint/tree/master/docs/rules'
6-
return sassLintDocs + '/' + ruleId + '.md'
12+
return SASSLINT_DOC_URL + '/' + ruleId + '.md'
13+
14+
###*
15+
* Function to check a file base / extension for valid extensions to use with sass-lint
16+
* @param {string} syntax - The syntax to check
17+
* @return {boolean} Whether or not the syntax is valid for sass-lint
18+
###
19+
isValidSyntax: (syntax) ->
20+
return VALID_SYNTAXES.indexOf(syntax) isnt -1
21+
22+
###*
23+
* Function to check a file base / extension for valid extensions to use with sass-lint
24+
* @param {string} filePath - The filepath to check
25+
* @return {string} The syntax we wish to pass to sass-lint
26+
###
27+
getFileSyntax: (filePath) ->
28+
existingSyntax = path.extname(filePath).slice(1)
29+
if @isValidSyntax(existingSyntax) is false
30+
base = path.parse(filePath).base.split('.')
31+
syntax = (item for item in base when @isValidSyntax(item))
32+
if syntax.length
33+
return syntax[0]
34+
35+
return existingSyntax

lib/main.coffee

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ module.exports =
7575
provideLinter: ->
7676
{find} = require 'atom-linter'
7777
globule = require 'globule'
78-
{getRuleURI} = require './helpers'
78+
helpers = require './helpers'
7979

8080
provider =
8181
name: 'sass-lint'
@@ -136,7 +136,7 @@ module.exports =
136136
if globule.isMatch(compiledConfig.files.include, relativePath) and not globule.isMatch(compiledConfig.files.ignore, relativePath)
137137
result = linter.lintText({
138138
text: editor.getText(),
139-
format: path.extname(filePath).slice(1),
139+
format: helpers.getFileSyntax(filePath),
140140
filename: filePath
141141
}, {}, config)
142142
catch error
@@ -169,7 +169,7 @@ module.exports =
169169
line = if msg.line then msg.line - 1 else 0
170170
col = if msg.column then msg.column - 1 else 0
171171
text = if msg.message then ' ' + msg.message else 'Unknown Error'
172-
ruleHref = getRuleURI(msg.ruleId)
172+
ruleHref = helpers.getRuleURI(msg.ruleId)
173173
html = '<a href="'+ ruleHref + '" class="badge badge-flexible sass-lint">' + msg.ruleId + '</a>' + text
174174

175175
result = {

spec/helpers-spec.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
'use babel';
2+
3+
import { SASSLINT_DOC_URL } from '../lib/constants.coffee';
4+
5+
const helpers = require('../lib/helpers.coffee');
6+
7+
describe('helpers', () => {
8+
describe('getRuleURI', () => {
9+
it('should return the correct rule URL', () => {
10+
const ruleId = 'no-ids';
11+
const result = helpers.getRuleURI(ruleId);
12+
13+
expect(result).toEqual(`${SASSLINT_DOC_URL}/${ruleId}.md`);
14+
});
15+
});
16+
17+
describe('isValidSyntax', () => {
18+
it('should return true if a supported syntax is passed', () => {
19+
expect(helpers.isValidSyntax('scss')).toEqual(true);
20+
});
21+
22+
it('should return false if a supported syntax is not passed', () => {
23+
expect(helpers.isValidSyntax('html')).toEqual(false);
24+
});
25+
});
26+
27+
describe('getFileSyntax', () => {
28+
it('it should return scss if a scss filename is provided', () => {
29+
expect(helpers.getFileSyntax('test/file.scss')).toEqual('scss');
30+
});
31+
32+
it('it should return sass if a sass filename is provided', () => {
33+
expect(helpers.getFileSyntax('test/file.sass')).toEqual('sass');
34+
});
35+
36+
it('it should return scss if a scss.liquid filename is provided', () => {
37+
expect(helpers.getFileSyntax('test/file.scss.liquid')).toEqual('scss');
38+
});
39+
40+
it('it should return sass if a sass.liquid filename is provided', () => {
41+
expect(helpers.getFileSyntax('test/file.sass.liquid')).toEqual('sass');
42+
});
43+
44+
it('it should return html if a html filename is provided', () => {
45+
expect(helpers.getFileSyntax('test/file.html')).toEqual('html');
46+
});
47+
});
48+
});

0 commit comments

Comments
 (0)