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

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
cbodin committed Mar 8, 2019
0 parents commit 3e3f7b7
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.DS_Store
.idea
node_modules
7 changes: 7 additions & 0 deletions .stylelintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "stylelint-config-standard",
"rules": {
"value-no-vendor-prefix": true,
"property-no-vendor-prefix": true
}
}
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Quicklint Stylelint
======
A CLI wrapping a simple stylelint config based on [stylelint-config-standard](https://github.com/stylelint/stylelint-config-standard).

The rules/options that differ from the standard:
- [value-no-vendor-prefix](https://stylelint.io/user-guide/rules/value-no-vendor-prefix/) set to `true` as [autoprefixer](https://github.com/postcss/autoprefixer) should be used
- [property-no-vendor-prefix](https://stylelint.io/user-guide/rules/property-no-vendor-prefix/) set to `true` as [autoprefixer](https://github.com/postcss/autoprefixer) should be used


Installation
------
Add the package as a dev dependency:
```bash
npm i -D github:cbodin/quicklint-stylelint#v1.0.0
```


Usage
------
The default behavior is to lint all the `.pcss` and `.css` files in the `src/` folder.
If any other folders should be used, the search paths can be specified with the `--paths` argument.

To include both the default `src/` folder and a `server/` folder, both paths will need to be supplied:
```bash
quicklint-stylelint --paths src/,server/
```

Run `npx quicklint-stylelint -h` for a list of all options.

A common scenario is to include a test script in your `package.json` file:
```json
{
"scripts": {
"test": "quicklint-stylelint"
}
}
```
57 changes: 57 additions & 0 deletions bin/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env node

(function () {
const path = require('path');
const stylelint = require('stylelint');
const stylelintFormatterPretty = require('stylelint-formatter-pretty');
const { ArgumentParser } = require('argparse');

// Load package config
const packageConfig = path.resolve(__dirname, '../package.json');
const packageInfo = require(packageConfig);

// Configure arguments
const parser = new ArgumentParser({
version: packageInfo.version,
description: packageInfo.description,
});
parser.addArgument(['--paths'], {
help: 'Define search paths, comma separated. Default "src/"',
defaultValue: 'src/',
});

// Check arguments
const args = parser.parseArgs();

// Create file globs of all paths
const globs = [];
const extensions = ['.pcss', '.css'];

for (const extension of extensions) {
for (const folderPath of args.paths.split(',')) {
const folder = path.resolve(process.cwd(), folderPath);
globs.push(path.resolve(folder, `*${extension}`));
globs.push(path.resolve(folder, '**', `*${extension}`));
}
}

console.log(`\x1b[34m ➜ Running Stylelint.\x1b[0m`);

// Load stylelint config
const configPath = path.resolve(__dirname, '../.stylelintrc.json');
const baseConfig = require(configPath);

// Lint
stylelint.lint({
config: baseConfig,
files: globs,
formatter: stylelintFormatterPretty,
}).then((data) => {
if (data.errored) {
console.log(data.output);
process.exit(1);
}

console.log(`\x1b[32m ✔ No Stylelint errors.\x1b[0m`);
});
}());
22 changes: 22 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "@cbodin/quicklint-stylelint",
"version": "1.0.0",
"description": "Pre-configured Stylelint using stylelint-config-standard as a base, packaged in a simple CLI",
"author": "Christofer Bodin <[email protected]>",
"license": "MIT",
"private": true,
"repository": {
"type": "git",
"url": "git+https://github.com/cbodin/quicklint-stylelint.git"
},
"main": "./bin/cli.js",
"bin": {
"quicklint-stylelint": "./bin/cli.js"
},
"dependencies": {
"argparse": "^1.0.10",
"stylelint": "^9.10.1",
"stylelint-config-standard": "^18.2.0",
"stylelint-formatter-pretty": "^1.0.3"
}
}

0 comments on commit 3e3f7b7

Please sign in to comment.