Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Commit

Permalink
[changed] switched from [scss-lint](https://github.com/brigade/scss-lint
Browse files Browse the repository at this point in the history
) to [stylelint](http://stylelint.io/), no more ruby dependencies (yay!)
  • Loading branch information
thealjey committed Jan 21, 2017
1 parent 0ce882d commit b54893e
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 63 deletions.
23 changes: 0 additions & 23 deletions .scss-lint.yml

This file was deleted.

30 changes: 30 additions & 0 deletions .stylelintrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
extends: stylelint-config-standard
plugins: [ stylelint-scss ]
rules:
font-family-name-quotes: always-where-recommended
function-url-quotes: always
selector-attribute-quotes: always
string-quotes: double
at-rule-no-vendor-prefix: true
media-feature-name-no-vendor-prefix: true
property-no-vendor-prefix: true
selector-no-vendor-prefix: true
value-no-vendor-prefix: true
selector-no-qualifying-type: true
max-line-length: 120
scss/at-extend-no-missing-placeholder: true
scss/at-import-no-partial-leading-underscore: true
scss/at-mixin-argumentless-call-parentheses: always
scss/dollar-variable-colon-space-after: always
scss/dollar-variable-colon-space-before: never
scss/double-slash-comment-empty-line-before: always
scss/double-slash-comment-inline: never
scss/double-slash-comment-whitespace-inside: always
scss/declaration-nested-properties: [ always, except: [ only-of-namespace ] ]
scss/declaration-nested-properties-no-divided-groups: true
scss/media-feature-value-dollar-variable: always
scss/operator-no-newline-after: true
scss/operator-no-newline-before: true
scss/operator-no-unspaced: true
scss/selector-no-redundant-nesting-selector: true
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ Any feedback on [Discord] would be greatly appreciated. It does not require regi
### Prerequisites

1. [Facebook Flow](http://flowtype.org/)
2. [SCSS-Lint](https://github.com/brigade/scss-lint)
2. [Watchman](https://facebook.github.io/watchman/)

### A note about [Facebook Flow](http://flowtype.org/)
Expand Down
19 changes: 19 additions & 0 deletions interfaces/stylelint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* @flow */

type StyleLintResult = {
source: string;
warnings: Array<{
line: number;
column: number;
text: string;
rule: string;
}>;
};

declare module 'stylelint' {
declare function lint(options: Object): {
then(callback: (result: {results: StyleLintResult[]}) => void): {
catch(callback: (error: Error) => void): void;
};
};
}
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@
"react-hot-loader": "^1.3.0",
"remarkable": "^1.6.2",
"serve-static": "^1.11.1",
"stylelint": "^7.7.1",
"stylelint-config-standard": "^15.0.1",
"stylelint-scss": "^1.4.1",
"tiny-lr": "^0.2.1",
"webpack": "^1.13.2",
"webpack-dev-server": "^1.15.1"
Expand Down
40 changes: 34 additions & 6 deletions src/SASS.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import {SASSCompiler} from './SASSCompiler';
import {SASSLint} from './SASSLint';
import noop from 'lodash/noop';
import {logLintingErrors} from './logger';

/**
* SASS compilation tools
Expand All @@ -20,7 +21,7 @@ import noop from 'lodash/noop';
* @class SASS
* @param {boolean} [compress=true] - if true `Compiler#save` will gzip compress the data
* @param {Array<string>} [includePaths=[]] - an array of additional include paths
* @param {Array<string>} [excludeLinter=[]] - names of linters to exclude
* @param {Object} [configOverrides={}] - an object that lets you override the default linting configuration
* @param {Object} [importOnceOptions={}] - an object that lets you override default importOnce resolver
* configuration
* @example
Expand All @@ -32,6 +33,7 @@ import noop from 'lodash/noop';
* const sass = new SASS();
*/
export class SASS {

/**
* SCSS compiler
*
Expand All @@ -52,11 +54,35 @@ export class SASS {
linter: SASSLint;

/* eslint-disable require-jsdoc */
constructor(compress: boolean = true, includePaths: Array<string> = [], excludeLinter: Array<string> = [],
constructor(compress: boolean = true, includePaths: Array<string> = [], configOverrides: Object = {},
importOnceOptions: Object = {}) {
/* eslint-enable require-jsdoc */
this.compiler = new SASSCompiler(compress, includePaths, importOnceOptions);
this.linter = new SASSLint(...excludeLinter);
this.linter = new SASSLint(configOverrides);
}

/**
* Performs linting
*
* @memberof SASS
* @instance
* @method lint
* @param {Array<string>} paths - an array of file globs. Ultimately passed to
* [node-glob](https://github.com/isaacs/node-glob) to figure out what files you
* want to lint.
* @param {Function} callback - a callback function, invoked only when successfully linted
* @example
* js.lint(paths, () => {
* // successfully linted
* });
*/
lint(paths: Array<string>, callback: () => void) {
this.linter.run(paths, linterErr => {
if (linterErr) {
return logLintingErrors(linterErr, 'SASS');
}
callback();
});
}

/**
Expand All @@ -67,16 +93,18 @@ export class SASS {
* @method fe
* @param {string} inPath - the input path
* @param {string} outPath - the output path
* @param {Array<string>} [lintPaths=[]] - an array of paths to files/directories to lint
* @param {Array<string>} [lintPaths=[]] - an array of file globs. Ultimately passed to
* [node-glob](https://github.com/isaacs/node-glob) to figure out
* what files you want to lint.
* @param {Function} [callback=function () {}] - a callback function
* @return {void}
* @example
* compiler.fe('/path/to/an/input/file.js', '/path/to/the/output/file.js', ['/lint/this/directory/too'], () => {
* compiler.fe(inPath, outPath, lintPaths, () => {
* // the code has passed all the checks and has been compiled successfully
* });
*/
fe(inPath: string, outPath: string, lintPaths: Array<string> = [], callback: () => void = noop) {
this.linter.run(lintPaths.concat([inPath]), () => {
this.lint(lintPaths.concat([inPath]), () => {
this.compiler.fe(inPath, outPath, callback);
});
}
Expand Down
68 changes: 35 additions & 33 deletions src/SASSLint.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
/* @flow */

import {NativeProcess} from './NativeProcess';
import type {LintCallback} from './typedef';
import {join} from 'path';
import forEach from 'lodash/forEach';
import {lint} from 'stylelint';
import {logError} from './logger';

const config = join(__dirname, '..', '.scss-lint.yml');
/* eslint-disable lodash/prefer-map */

const configFile = join(__dirname, '..', '.stylelintrc.yaml');

/**
* A SASS linter
*
* @class SASSLint
* @param {...string} excludeLinter - names of linters to exclude
* @param {Object} [configOverrides={}] - an object that lets you override the default linting configuration
* @see {@link http://stylelint.io/ stylelint}
* @example
* import {SASSLint} from 'webcompiler';
* // or - import {SASSLint} from 'webcompiler/lib/SASSLint';
Expand All @@ -20,29 +26,21 @@ const config = join(__dirname, '..', '.scss-lint.yml');
* const linter = new SASSLint();
*/
export class SASSLint {
/**
* a comma-separated list of linter names to exclude from execution
*
* @member {string} excludeLinter
* @memberof SASSLint
* @private
* @instance
*/
excludeLinter: string;

/**
* a NativeProcess instance for scss-lint
* stylelint configOverrides
*
* @member {NativeProcess} proc
* @member {Object} configOverrides
* @memberof SASSLint
* @private
* @instance
*/
proc: NativeProcess = new NativeProcess('scss-lint');
configOverrides: Object;

/** @constructs */
constructor(...excludeLinter: Array<string>) {
this.excludeLinter = excludeLinter.join(',');
/* eslint-disable require-jsdoc */
constructor(configOverrides: Object = {}) {
/* eslint-enable require-jsdoc */
this.configOverrides = configOverrides;
}

/**
Expand All @@ -51,28 +49,32 @@ export class SASSLint {
* @memberof SASSLint
* @instance
* @method run
* @param {Array<string>} paths - an array of paths to files/directories to lint
* @param {Function} callback - a callback function, executed only on success
* @param {Array<string>} paths - an array of file globs. Ultimately passed to
* [node-glob](https://github.com/isaacs/node-glob) to figure out what files you
* want to lint.
* @param {LintCallback} callback - a callback function
* @example
* import {logLintingErrors} from 'webcompiler';
*
* // lint "style.scss" as well as the entire contents of the "sass" directory
* linter.run([join(__dirname, 'style.scss'), join(__dirname, 'sass')], error => {
* if (error) {
* return console.error(error);
* linter.run([join(__dirname, 'style.scss'), join(__dirname, 'sass', '**', '*.scss')], errors => {
* if (errors) {
* return logLintingErrors(errors);
* }
* // there were no linting errors
* });
*/
run(paths: Array<string>, callback: () => void) {
const args = paths.concat(['-c', config]);
run(paths: Array<string>, callback: LintCallback) {
lint({configFile, configOverrides: this.configOverrides, files: paths}).then(({results}) => {
const errors = [];

if (this.excludeLinter) {
args.push('-x', this.excludeLinter);
}
this.proc.run(stderr => {
if (null === stderr) {
callback();
}
}, args, {stdio: 'inherit'});
forEach(results, ({source: file, warnings}) => {
forEach(warnings, ({line, column, text, rule}) => {
errors.push({file, line, column, message: text.replace(new RegExp(`\\s*\\(${rule}\\)$`), ''), rule});
});
});
callback(errors.length ? errors : null);
}).catch(logError);
}

}

0 comments on commit b54893e

Please sign in to comment.