This repository has been archived by the owner on Oct 19, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
1,201 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/node_modules | ||
/npm-debug.log |
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,2 @@ | ||
#!/usr/bin/env node | ||
require('../lib/cli')(process.argv) |
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,23 @@ | ||
#!/usr/bin/env node | ||
const program = require('commander') | ||
const packageDetails = require('./../package.json') | ||
const Linter = require('./linter.js') | ||
|
||
const run = (args) => { | ||
program | ||
.version(packageDetails.version) | ||
.description(packageDetails.description) | ||
.usage('[options] <paths ...>') | ||
.arguments('<paths>') | ||
.parse(process.argv) | ||
|
||
if (!program.args.length) { | ||
program.help() | ||
} | ||
|
||
const linter = new Linter() | ||
|
||
linter.checkPaths(program.args) | ||
} | ||
|
||
module.exports = run |
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,80 @@ | ||
const walk = require('walk') | ||
const fs = require('fs') | ||
const path = require('path') | ||
const htmlparser = require('htmlparser') | ||
const cheerio = require('cheerio') | ||
const sassLint = require('sass-lint') | ||
const Reporter = require('./reporter.js') | ||
|
||
class Linter { | ||
constructor (options) { | ||
this.lintErrors = [] | ||
} | ||
|
||
checkPaths (pathsToCheck) { | ||
pathsToCheck.forEach((pathToCheck) => { | ||
this.checkPath(pathToCheck) | ||
}) | ||
} | ||
|
||
checkPath (arg) { | ||
const walker = walk.walk(arg, { followLinks: false }) | ||
walker.on('file', this.walkerFileHandler.bind(this)) | ||
walker.on('end', this.walkerEndHandler.bind(this)) | ||
} | ||
|
||
walkerFileHandler (root, fileStat, next) { | ||
const filename = `${root}/${fileStat.name}` | ||
|
||
if (filename.substr(-3) !== 'vue') { | ||
return next() | ||
} | ||
|
||
fs.readFile(path.resolve(root, fileStat.name), (error, fileData) => { | ||
if (error) { | ||
return console.log(error) | ||
} | ||
|
||
const fileTemplates = this.extractFileTemplates(fileData) | ||
|
||
fileTemplates.forEach((template) => { | ||
const fileErrors = sassLint.lintText({ | ||
text: template, | ||
filename: filename, | ||
format: 'scss' | ||
}) | ||
|
||
if (fileErrors.messages.length) { | ||
this.lintErrors = this.lintErrors.concat(fileErrors) | ||
} | ||
}) | ||
|
||
next() | ||
}) | ||
} | ||
|
||
walkerEndHandler () { | ||
const reporter = new Reporter() | ||
reporter.report(this.lintErrors) | ||
} | ||
|
||
extractFileTemplates (fileData) { | ||
let templates = [] | ||
|
||
const handler = new htmlparser.DefaultHandler((error, dom) => { | ||
if (error) { | ||
return console.log(error) | ||
} | ||
|
||
const $ = cheerio.load(dom) | ||
templates = templates.concat($('style[lang="sass"]').text()) | ||
templates = templates.concat($('style[lang="scss"]').text()) | ||
}) | ||
|
||
var parser = new htmlparser.Parser(handler) | ||
parser.parseComplete(fileData) | ||
return templates | ||
} | ||
} | ||
|
||
module.exports = Linter |
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,38 @@ | ||
const table = require('text-table') | ||
const chalk = require('chalk') | ||
|
||
class Reporter { | ||
report (results) { | ||
let output = '\n' | ||
let totalErrors = 0 | ||
let totalWarnings = 0 | ||
|
||
results.forEach((result) => { | ||
totalErrors += result.errorCount | ||
totalWarnings += result.warningCount | ||
|
||
output += chalk.underline(result.filePath) + '\n' | ||
|
||
output += table(result.messages.map((msg) => { | ||
return [ | ||
'', | ||
`${msg.line}:${msg.column}`, | ||
(msg.severity === 2) ? chalk.red(msg.ruleId) : chalk.yellow(msg.ruleId), | ||
msg.message | ||
] | ||
})) | ||
|
||
output += '\n\n' | ||
}) | ||
|
||
if (totalErrors > 0) { | ||
output += chalk.red.bold(`\u2716 errors: ${totalErrors}`) | ||
output += ' | ' | ||
output += chalk.yellow.bold(`warnings ${totalWarnings}`) | ||
console.log(output) | ||
process.exit(1) | ||
} | ||
} | ||
} | ||
|
||
module.exports = Reporter |
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,37 @@ | ||
{ | ||
"name": "sass-lint-vue", | ||
"version": "0.1.0", | ||
"description": "Command line tool to lint Sass styles in Vue single file components.", | ||
"keywords": [ | ||
"lint", | ||
"linting", | ||
"linter", | ||
"sass", | ||
"scss", | ||
"vue" | ||
], | ||
"homepage": "https://github.com/sourceboat/sass-lint-vue", | ||
"bugs": "https://github.com/sourceboat/sass-lint-vue/issues", | ||
"author": "Sourceboat <info@sourceboat.com>", | ||
"contributors": [ | ||
"Phil-Bastian Berndt <me@pbb.io> (https://pbb.io/)" | ||
], | ||
"license": "MIT", | ||
"repository": { | ||
"url": "https://github.com/sourceboat/sass-lint-vue", | ||
"type": "git" | ||
}, | ||
"main": "lib/linter.js", | ||
"bin": { | ||
"sass-lint-vue": "./bin/sass-lint-vue" | ||
}, | ||
"dependencies": { | ||
"chalk": "^1.1.3", | ||
"cheerio": "^0.22.0", | ||
"commander": "^2.9.0", | ||
"htmlparser": "^1.7.7", | ||
"sass-lint": "^1.10.2", | ||
"text-table": "^0.2.0", | ||
"walk": "^2.3.9" | ||
} | ||
} |
Oops, something went wrong.