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 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #93 from AtomLinter/feature/support-syntaxes
Add helper tests constants and support extra syntaxes
- Loading branch information
Showing
6 changed files
with
98 additions
and
6 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
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = | ||
SASSLINT_DOC_URL: 'https://github.com/sasstools/sass-lint/tree/master/docs/rules', | ||
VALID_SYNTAXES: ['scss', 'sass'] |
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,6 +1,35 @@ | ||
path = require 'path' | ||
{SASSLINT_DOC_URL, VALID_SYNTAXES} = require './constants.coffee' | ||
|
||
module.exports = | ||
|
||
# Constructs the rule URI from the rule ID provided | ||
###* | ||
* Function to construct the rule URI from the rule ID provided | ||
* @param {string} ruleId - The rule name / id | ||
* @return {string} The rule URL | ||
### | ||
getRuleURI: (ruleId) -> | ||
sassLintDocs = 'https://github.com/sasstools/sass-lint/tree/master/docs/rules' | ||
return sassLintDocs + '/' + ruleId + '.md' | ||
return SASSLINT_DOC_URL + '/' + ruleId + '.md' | ||
|
||
###* | ||
* Function to check a file base / extension for valid extensions to use with sass-lint | ||
* @param {string} syntax - The syntax to check | ||
* @return {boolean} Whether or not the syntax is valid for sass-lint | ||
### | ||
isValidSyntax: (syntax) -> | ||
return VALID_SYNTAXES.indexOf(syntax) isnt -1 | ||
|
||
###* | ||
* Function to check a file base / extension for valid extensions to use with sass-lint | ||
* @param {string} filePath - The filepath to check | ||
* @return {string} The syntax we wish to pass to sass-lint | ||
### | ||
getFileSyntax: (filePath) -> | ||
existingSyntax = path.extname(filePath).slice(1) | ||
if @isValidSyntax(existingSyntax) is false | ||
base = path.parse(filePath).base.split('.') | ||
syntax = (item for item in base when @isValidSyntax(item)) | ||
if syntax.length | ||
return syntax[0] | ||
|
||
return existingSyntax |
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
'use babel'; | ||
|
||
import { SASSLINT_DOC_URL } from '../lib/constants.coffee'; | ||
|
||
const helpers = require('../lib/helpers.coffee'); | ||
|
||
describe('helpers', () => { | ||
describe('getRuleURI', () => { | ||
it('should return the correct rule URL', () => { | ||
const ruleId = 'no-ids'; | ||
const result = helpers.getRuleURI(ruleId); | ||
|
||
expect(result).toEqual(`${SASSLINT_DOC_URL}/${ruleId}.md`); | ||
}); | ||
}); | ||
|
||
describe('isValidSyntax', () => { | ||
it('should return true if a supported syntax is passed', () => { | ||
expect(helpers.isValidSyntax('scss')).toEqual(true); | ||
}); | ||
|
||
it('should return false if a supported syntax is not passed', () => { | ||
expect(helpers.isValidSyntax('html')).toEqual(false); | ||
}); | ||
}); | ||
|
||
describe('getFileSyntax', () => { | ||
it('it should return scss if a scss filename is provided', () => { | ||
expect(helpers.getFileSyntax('test/file.scss')).toEqual('scss'); | ||
}); | ||
|
||
it('it should return sass if a sass filename is provided', () => { | ||
expect(helpers.getFileSyntax('test/file.sass')).toEqual('sass'); | ||
}); | ||
|
||
it('it should return scss if a scss.liquid filename is provided', () => { | ||
expect(helpers.getFileSyntax('test/file.scss.liquid')).toEqual('scss'); | ||
}); | ||
|
||
it('it should return sass if a sass.liquid filename is provided', () => { | ||
expect(helpers.getFileSyntax('test/file.sass.liquid')).toEqual('sass'); | ||
}); | ||
|
||
it('it should return html if a html filename is provided', () => { | ||
expect(helpers.getFileSyntax('test/file.html')).toEqual('html'); | ||
}); | ||
}); | ||
}); |