diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..ae10a5c --- /dev/null +++ b/.editorconfig @@ -0,0 +1,10 @@ +# editorconfig.org +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 2 +indent_style = space +insert_final_newline = true +trim_trailing_whitespace = true diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..fcadb2c --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text eol=lf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d5f19d8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules +package-lock.json diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..6d1e400 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,23 @@ +sudo: false + +git: + depth: 1 + +branches: + only: + - master + +language: node_js + +# cache node modules +cache: + directories: + - node_modules + +node_js: + - '8' + - '6' + +before_install: + # remove outdated deps, assists with cache maintenance + - npm prune diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..8eb7afb --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,3 @@ +# 0.1.0 + +- Initial release diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..b73e8bb --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2017 stylelint + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 05b18ad..6adb2d3 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,58 @@ # stylelint-config-recommended -The recommended shareable config for stylelint + +[![NPM version](http://img.shields.io/npm/v/stylelint-config-recommended.svg)](https://www.npmjs.org/package/stylelint-config-recommended) [![Build Status](https://travis-ci.org/stylelint/stylelint-config-recommended.svg?branch=master)](https://travis-ci.org/stylelint/stylelint-config-recommended) [![Build status](https://ci.appveyor.com/api/projects/status/o8rfhyax6n7bjnlt/branch/master?svg=true)](https://ci.appveyor.com/project/stylelint/stylelint-config-recommended/branch/master) + +> The recommended shareable config for stylelint. + +It turns on all the _possible errors_ rules within stylelint. + +Use it as is or as a foundation for your own config. + +## Installation + +```bash +npm install stylelint-config-recommended --save-dev +``` + +## Usage + +If you've installed `stylelint-config-recommended` locally within your project, just set your `stylelint` config to: + +```json +{ + "extends": "stylelint-config-recommended" +} +``` + +If you've globally installed `stylelint-config-recommended` using the `-g` flag, then you'll need to use the absolute path to `stylelint-config-recommended` in your config e.g. + +```json +{ + "extends": "/absolute/path/to/stylelint-config-recommended" +} +``` + +### Extending the config + +Simply add a `"rules"` key to your config, then add your overrides and additions there. + +For example, to turn off the `block-no-empty` rule, change the `property-no-unknown` rule to use its `ignoreAtRules` option and add the `unit-whitelist` rule: + +```json +{ + "extends": "stylelint-config-recommended", + "rules": { + "block-no-empty": "tab", + "property-no-unknown": [ true, { + "ignoreProperties": [ + "composes" + ] + }], + "unit-whitelist": ["em", "rem", "s"] + } +} +``` + +## [Changelog](CHANGELOG.md) + +## [License](LICENSE) diff --git a/__tests__/css-invalid.css b/__tests__/css-invalid.css new file mode 100644 index 0000000..4fb356c --- /dev/null +++ b/__tests__/css-invalid.css @@ -0,0 +1,3 @@ +madeup { + top: 0; +} diff --git a/__tests__/css-valid.css b/__tests__/css-valid.css new file mode 100644 index 0000000..ccbd096 --- /dev/null +++ b/__tests__/css-valid.css @@ -0,0 +1,10 @@ +@import url(x.css); + +.selector-1, +.selector-2, +.selector-3[type="text"] { + background: linear-gradient(#fff, rgba(0, 0, 0, 0.8)); + box-sizing: border-box; + display: block; + color: #333; +} diff --git a/__tests__/index.js b/__tests__/index.js new file mode 100644 index 0000000..6b6c139 --- /dev/null +++ b/__tests__/index.js @@ -0,0 +1,84 @@ +"use strict" + +const fs = require("fs") +const config = require("../") +const stylelint = require("stylelint") + +const validCss = fs.readFileSync("./__tests__/css-valid.css", "utf-8") +const invalidCss = fs.readFileSync("./__tests__/css-invalid.css", "utf-8") + +describe("flags no warnings with valid css", () => { + let result + + beforeEach(() => { + result = stylelint.lint({ + code: validCss, + config, + }) + }) + + it("did not error", () => { + return result.then(data => ( + expect(data.errored).toBeFalsy() + )) + }) + + it("flags no warnings", () => { + return result.then(data => ( + expect(data.results[0].warnings.length).toBe(0) + )) + }) +}) + +describe("flags warnings with invalid css", () => { + let result + + beforeEach(() => { + result = stylelint.lint({ + code: invalidCss, + config, + }) + }) + + it("did error", () => { + return result.then(data => ( + expect(data.errored).toBeTruthy() + )) + }) + + it("flags one warning", () => { + return result.then(data => ( + expect(data.results[0].warnings.length).toBe(1) + )) + }) + + it("correct warning text", () => { + return result.then(data => ( + expect(data.results[0].warnings[0].text).toBe("Unexpected unknown type selector \"madeup\" (selector-type-no-unknown)") + )) + }) + + it("correct rule flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[0].rule).toBe("selector-type-no-unknown") + )) + }) + + it("correct severity flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[0].severity).toBe("error") + )) + }) + + it("correct line number", () => { + return result.then(data => ( + expect(data.results[0].warnings[0].line).toBe(1) + )) + }) + + it("correct column number", () => { + return result.then(data => ( + expect(data.results[0].warnings[0].column).toBe(1) + )) + }) +}) diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..e9f2117 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,22 @@ +# http://www.appveyor.com/docs/appveyor-yml + +environment: + matrix: + - nodejs_version: 6 + +version: "{build}" +build: off +deploy: off +branches: + only: + - master +clone_depth: 1 +skip_tags: true +install: + - ps: Install-Product node $env:nodejs_version + - npm install + +test_script: + - node --version + - npm --version + - cmd: "npm test" diff --git a/index.js b/index.js new file mode 100644 index 0000000..acafed4 --- /dev/null +++ b/index.js @@ -0,0 +1,30 @@ +"use strict" + +module.exports = { + "rules": { + "at-rule-no-unknown": true, + "block-no-empty": true, + "color-no-invalid-hex": true, + "comment-no-empty": true, + "declaration-block-no-duplicate-properties": [ true, { + ignore: ["consecutive-duplicates-with-different-values"], + } ], + "declaration-block-no-redundant-longhand-properties": true, + "declaration-block-no-shorthand-property-overrides": true, + "font-family-no-duplicate-names": true, + "function-calc-no-unspaced-operator": true, + "function-linear-gradient-no-nonstandard-direction": true, + "keyframe-declaration-no-important": true, + "media-feature-name-no-unknown": true, + "no-empty-source": true, + "no-extra-semicolons": true, + "no-invalid-double-slash-comments": true, + "property-no-unknown": true, + "selector-pseudo-class-no-unknown": true, + "selector-pseudo-element-no-unknown": true, + "selector-type-no-unknown": true, + "shorthand-property-no-redundant-values": true, + "string-no-newline": true, + "unit-no-unknown": true, + }, +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..5fbf523 --- /dev/null +++ b/package.json @@ -0,0 +1,58 @@ +{ + "name": "stylelint-config-recommended", + "version": "0.1.0", + "description": "Recommended shareable config for stylelint", + "keywords": [ + "stylelint", + "stylelint-config", + "recommended" + ], + "author": "stylelint", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/stylelint/stylelint-config-recommended.git" + }, + "main": "index.js", + "files": [ + "index.js" + ], + "devDependencies": { + "eslint": "^4.1.0", + "eslint-config-stylelint": "^6.0.0", + "jest": "^20.0.0", + "npm-run-all": "^4.0.0", + "npmpub": "^3.0.1", + "remark-cli": "^3.0.0", + "remark-preset-lint-consistent": "^2.0.0", + "remark-preset-lint-recommended": "^2.0.0", + "stylelint": "^7.12.0" + }, + "peerDependencies": { + "stylelint": "^7.8.0" + }, + "scripts": { + "lint:js": "eslint . --ignore-path .gitignore", + "lint:md": "remark . --quiet --frail", + "lint": "npm-run-all --parallel lint:*", + "pretest": "npm run lint", + "release": "npmpub", + "test": "jest", + "watch": "jest --watch" + }, + "eslintConfig": { + "extends": [ + "stylelint" + ] + }, + "jest": { + "testEnvironment": "node", + "verbose": true + }, + "remarkConfig": { + "plugins": [ + "preset-lint-recommended", + "preset-lint-consistent" + ] + } +}