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

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: sourceboat/sass-lint-vue
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.3.3
Choose a base ref
...
head repository: sourceboat/sass-lint-vue
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: develop
Choose a head ref
Loading
Showing with 1,209 additions and 358 deletions.
  1. +4 −1 .travis.yml
  2. +13 −1 Dockerfile
  3. +1 −1 license.md → LICENSE.md
  4. +15 −6 readme.md → README.md
  5. +7 −0 docker-compose.yml
  6. +2 −2 lib/cli.js
  7. +35 −15 lib/linter.js
  8. +8 −6 package.json
  9. +14 −0 test/ComponentSass.vue
  10. +1,110 −326 yarn.lock
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
language: node_js
node_js:
- '6'
- '8'
- '10'
cache:
yarn: true
script:
- yarn run lint
notifications:
slack:
secure: np7HDSwnl/LPafSpmurP1WMwC7fVeOkUkhf921zY08ICRlt1LkLhzHaus7aqEEwQiTwBXXRVTYmaWkIakFrEarEFGKly9vfpsWAibTfeRTZycXJcr7GPdgr3M3HmzaEGSGc4C/CsRJ/Swvq29MFUa0xTf1lZ+gBnMARoqDs5ODF321SLqfwge7k3G58P7ITK5OQ8QftEyXzSZ/Ar2Xb3oMlZZMKTbv9EREYO2ONFdG6KT6HiygZ2Ah9Dp34HbnmXA6nikbJWOWwPZvAfSf6hCtemSxAlicSWlcndN275VeM2Q+qCtIfFnRHUth1plR72x3d5N0O7E9RQp2J2RmceUMaH6NzK7oRZQZAirYZjvl6dw/BkprjnkLmk3cBVx0SuFK/DkWUwPwaNNoRzX3iFnrmFkRCw4LND5mBWC6Pmfb3Y/qtOC25kdIpzjVQG50yXNrXd9GMS1aSsyOHIlccBtB8/L7jzYGGi5hJTOeC7NVl/KIxk291s/XVHc+ZNsdNgMNvSNXJDxEph9Tt4xwtETla7ETejtgnwRzBedD1UeID0S7+PeU22Pt0jdb1YI5G7SVLllm8ZgnlcajlcUZTZ+mr/8S8L9wzt3NFOca3prWiORIR9EAFoWhqIhIxJFzaDyt0Xew8BsOEfP5SUxH6UkTBiSWnhhouhatHDzLC6p5c=
on_success: never
on_failure: always
14 changes: 13 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
FROM node:8
FROM node:10

WORKDIR /app

# Install dependencies
COPY package.json yarn.* ./
RUN yarn install

# Copy our code on top
COPY lib ./lib
COPY bin ./bin

ENTRYPOINT ["bin/sass-lint-vue"]
2 changes: 1 addition & 1 deletion license.md → LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MIT License

Copyright (c) 2017 Sourceboat
Copyright (c) Sourceboat GmbH & Co. KG <info@sourceboat.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
21 changes: 15 additions & 6 deletions readme.md → README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
:warning: **Deprecated:** This project is not actively maintained anymore. Use it at your own risk. The underlying library [sass-lint](https://github.com/sasstools/sass-lint) is unmaintained. We recommend using [stylelint](https://vue-loader.vuejs.org/guide/linting.html#stylelint) to lint your single file components directly.

# sass-lint-vue

[![npm](https://img.shields.io/npm/v/sass-lint-vue.svg?style=flat-square)](https://www.npmjs.com/package/sass-lint-vue)
@@ -21,7 +23,7 @@ npm install sass-lint-vue
## Usage

```bash
sass-lint-vue [options] <file ...>
sass-lint-vue [options] <paths|file path ...>
```

### Options
@@ -31,28 +33,35 @@ sass-lint-vue [options] <file ...>

## Example

The following example scans the `assets` directory for `.vue` files and outputs lint errors in `<style>` tags with the attribute `lang="scss"` set.
The following example scans the `assets` directory for `.vue` files and outputs lint errors in `<style>` tags with the attribute `lang="scss"` or `lang="sass"` set.

```bash
sass-lint-vue assets
```

## Development

Build the docker container via
Build the docker container via:

```bash
docker build . -t sass-lint-vue.
$ docker build . -t sass-lint-vue
```

Lint the `Component.vue` file in the docker container via:

```bash
docker run --rm -v (pwd):/app sass-lint-vue ./app/bin/sass-lint-vue ./app/test/Component.vue
$ docker run --rm -tv $(pwd)/test:/app/test sass-lint-vue test
```

Access the container via:

```bash
docker run -it --rm -v (pwd):/app sass-lint-vue bash
$ docker run -it --rm -v $(pwd)/test:/app/test --entrypoint bash sass-lint-vue
```

Use docker compose to work on the files:

```
$ docker-compose up
$ docker-compose exec app bash
```
7 changes: 7 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: '3'
services:
app:
build: .
volumes:
- ./:/app
entrypoint: tail -F /dev/null
4 changes: 2 additions & 2 deletions lib/cli.js
Original file line number Diff line number Diff line change
@@ -7,8 +7,8 @@ const run = (args) => {
program
.version(packageDetails.version)
.description(packageDetails.description)
.usage('[options] <paths ...>')
.arguments('<paths>')
.usage('[options] <paths|file path ...>')
.arguments('<paths|file path>')
.parse(process.argv)

if (!program.args.length) {
50 changes: 35 additions & 15 deletions lib/linter.js
Original file line number Diff line number Diff line change
@@ -13,35 +13,48 @@ class Linter {

checkPaths (pathsToCheck) {
pathsToCheck.forEach((pathToCheck) => {
this.checkPath(pathToCheck)
if (pathToCheck.substr(-3) === 'vue') {
this.lintFile(pathToCheck, this.walkerEndHandler.bind(this))
} else {
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))
walker.on('errors', this.walkerErrorsHandler.bind(this))
}

walkerErrorsHandler (root, nodeStatsArray, next) {
console.error('Linting Error: Invalid sass linting path.')
console.log(nodeStatsArray)
next()
}

walkerFileHandler (root, fileStat, next) {
const filename = `${root}/${fileStat.name}`

if (filename.substr(-3) !== 'vue') {
return next()
}
this.lintFile(path.resolve(root, fileStat.name), next)
}

fs.readFile(path.resolve(root, fileStat.name), (error, fileData) => {
lintFile (filePath, next) {
fs.readFile(filePath, (error, fileData) => {
if (error) {
return console.log(error)
return console.error(error)
}

const fileTemplates = this.extractFileTemplates(fileData)

fileTemplates.forEach((template) => {
const fileErrors = sassLint.lintText({
text: template.content,
filename: filename,
format: 'scss'
filename: filePath,
format: template.format
})

if (fileErrors.messages.length) {
@@ -70,16 +83,23 @@ class Linter {
}

const $ = cheerio.load(dom)
const template = $('style[lang="scss"]').text()

if (template.length <= 0) {
return
const scssTemplate = $('style[lang="scss"]').text()
const sassTemplate = $('style[lang="sass"]').text()

if (scssTemplate.length) {
templates.push({
content: scssTemplate,
format: 'scss',
lineOffset: this.getLineOffset(scssTemplate, $.text())
})
}
if (sassTemplate.length) {
templates.push({
content: sassTemplate,
format: 'sass',
lineOffset: this.getLineOffset(sassTemplate, $.text())
})
}

templates.push({
content: template,
lineOffset: this.getLineOffset(template, $.text())
})
})

var parser = new htmlparser.Parser(handler)
14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sass-lint-vue",
"version": "0.3.3",
"version": "0.4.0",
"description": "Command line tool to lint Sass styles in Vue single file components.",
"keywords": [
"lint",
@@ -33,16 +33,18 @@
"chalk": "^2.4.1",
"cheerio": "^1.0.0-rc.2",
"commander": "^2.18.0",
"eslint": "^3.14.1",
"eslint-config-standard": "^6.2.1",
"eslint-plugin-promise": "^3.4.0",
"eslint-plugin-standard": "^2.0.1",
"htmlparser2": "^3.9.2",
"sass-lint": "^1.12.1",
"text-table": "^0.2.0",
"walk": "^2.3.14"
},
"devDependencies": {
"husky": "^1.0.1"
"eslint": "^5.16.0",
"eslint-config-standard": "^12.0.0",
"eslint-plugin-import": "^2.17.3",
"eslint-plugin-node": "^9.1.0",
"eslint-plugin-promise": "^4.1.1",
"eslint-plugin-standard": "^4.0.0",
"husky": "^2.4.1"
}
}
14 changes: 14 additions & 0 deletions test/ComponentSass.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<template>
<div class="wrapper"></div>
</template>
<script>
export default {
}
</script>
<style lang="sass">
.wrapper
$black: #000
background: $black
</style>
Loading