Skip to content
This repository was archived by the owner on Oct 19, 2020. It is now read-only.

Commit 1cab7db

Browse files
authored
Merge pull request #17 from Romick2005/filepath-linting
#16 Add file path linting functionality.
2 parents c828214 + 3ab43d8 commit 1cab7db

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

lib/cli.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ const run = (args) => {
77
program
88
.version(packageDetails.version)
99
.description(packageDetails.description)
10-
.usage('[options] <paths ...>')
11-
.arguments('<paths>')
10+
.usage('[options] <paths|file path ...>')
11+
.arguments('<paths|file path>')
1212
.parse(process.argv)
1313

1414
if (!program.args.length) {

lib/linter.js

+18-5
Original file line numberDiff line numberDiff line change
@@ -13,34 +13,47 @@ class Linter {
1313

1414
checkPaths (pathsToCheck) {
1515
pathsToCheck.forEach((pathToCheck) => {
16-
this.checkPath(pathToCheck)
16+
if (pathToCheck.substr(-3) === 'vue') {
17+
this.lintFile(pathToCheck, this.walkerEndHandler.bind(this))
18+
} else {
19+
this.checkPath(pathToCheck)
20+
}
1721
})
1822
}
1923

2024
checkPath (arg) {
2125
const walker = walk.walk(arg, { followLinks: false })
2226
walker.on('file', this.walkerFileHandler.bind(this))
2327
walker.on('end', this.walkerEndHandler.bind(this))
28+
walker.on('errors', this.walkerErrorsHandler.bind(this))
29+
}
30+
31+
walkerErrorsHandler (root, nodeStatsArray, next) {
32+
console.error('Linting Error: Invalid sass linting path.')
33+
console.log(nodeStatsArray)
34+
next()
2435
}
2536

2637
walkerFileHandler (root, fileStat, next) {
2738
const filename = `${root}/${fileStat.name}`
28-
2939
if (filename.substr(-3) !== 'vue') {
3040
return next()
3141
}
42+
this.lintFile(path.resolve(root, fileStat.name), next)
43+
}
3244

33-
fs.readFile(path.resolve(root, fileStat.name), (error, fileData) => {
45+
lintFile (filePath, next) {
46+
fs.readFile(filePath, (error, fileData) => {
3447
if (error) {
35-
return console.log(error)
48+
return console.error(error)
3649
}
3750

3851
const fileTemplates = this.extractFileTemplates(fileData)
3952

4053
fileTemplates.forEach((template) => {
4154
const fileErrors = sassLint.lintText({
4255
text: template.content,
43-
filename: filename,
56+
filename: filePath,
4457
format: 'scss'
4558
})
4659

0 commit comments

Comments
 (0)