1
1
mirror of https://github.com/primer/css.git synced 2024-12-24 06:32:00 +03:00

initial commit

This commit is contained in:
Jon Rohan 2016-06-14 10:23:10 -04:00
commit 1ac303e9a6
9 changed files with 576 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
node_modules

3
.npmignore Normal file
View File

@ -0,0 +1,3 @@
__tests__
*.yml
.github

12
.travis.yml Normal file
View File

@ -0,0 +1,12 @@
language: node_js
node_js:
- '5'
deploy:
provider: npm
email: ${NPM_EMAIL}
api_key: ${NPM_API_KEY}
skip_cleanup: true
on:
branch: master
repo: ${TRAVIS_REPO_SLUG}

3
CHANGELOG.md Normal file
View File

@ -0,0 +1,3 @@
# 1.0.0
- Creating a sharable config object

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2016 GitHub Inc.
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.

79
README.md Normal file
View File

@ -0,0 +1,79 @@
# Primer Stylelint Config
[![NPM version](http://img.shields.io/npm/v/stylelint-config-primer.svg)](https://www.npmjs.org/package/stylelint-config-primer)
[![Build Status](https://travis-ci.org/primer/stylelint-config-primer.svg?branch=master)](https://travis-ci.org/primer/stylelint-config-primer)
> A sharable stylelint config object that enforces GitHub's css rules
## Install
```
$ npm install --save stylelint-config-primer
```
## Usage
Within your [stylelint config object](http://stylelint.io/user-guide/configuration/#extends) You can extend this configuration. This will serve as a base for your config, then you can make overrides in your own config object.
```json
{
"extends": "stylelint-config-primer"
}
```
## Documentation
### Plugins
* [stylelint-scss](https://github.com/kristerkari/stylelint-scss): A collection of SCSS specific linting rules for stylelint
* [scss/selector-no-redundant-nesting-selector](https://github.com/kristerkari/stylelint-scss/blob/master/src/rules/selector-no-redundant-nesting-selector/README.md): Disallow redundant nesting selectors (`&`).
* [stylelint-selector-no-utility](https://github.com/primer/stylelint-selector-no-utility): Stylelint rule that doesn't allow the styling of utility classes in CSS
### Configured lints
This is a list of the lints turned on in this configuration, and what they do.
#### At-rule
* [at-rule-blacklist](http://stylelint.io/user-guide/rules/at-rule-blacklist/): `["extend"]` should never be used in `@rule`.
* [at-rule-name-case](http://stylelint.io/user-guide/rules/at-rule-name-case/): at rules must be in written lowercase.
* [at-rule-name-space-after](http://stylelint.io/user-guide/rules/at-rule-name-space-after/): There must always be a single space after at-rule names in single-line declaration blocks.
* [at-rule-semicolon-newline-after](http://stylelint.io/user-guide/rules/at-rule-semicolon-newline-after/): There must always be a newline after the semicolon.
#### Block
* [block-closing-brace-newline-after](http://stylelint.io/user-guide/rules/block-closing-brace-newline-after/): There must always be a newline after the closing brace.
* [block-closing-brace-newline-before](http://stylelint.io/user-guide/rules/block-closing-brace-newline-before/): There must always be a newline before the closing brace in multi-line blocks.
* [block-closing-brace-space-before](http://stylelint.io/user-guide/rules/block-closing-brace-space-before/): There must always be a single space before the closing brace in single-line blocks.
* [block-no-empty](http://stylelint.io/user-guide/rules/block-no-empty/): Disallow empty blocks.
* [block-opening-brace-newline-after](http://stylelint.io/user-guide/rules/block-opening-brace-newline-after/): There must always be a newline after the opening brace in multi-line blocks.
* [block-opening-brace-space-after](http://stylelint.io/user-guide/rules/block-opening-brace-space-after/): There must always be a single space after the opening brace in single-line blocks.
* [block-opening-brace-space-before](http://stylelint.io/user-guide/rules/block-opening-brace-space-before/): There must always be a single space before the opening brace.
#### Color
* [color-hex-case](http://stylelint.io/user-guide/rules/color-hex-case/): Hex colors must be written in lowercase.
* [color-hex-length](http://stylelint.io/user-guide/rules/color-hex-length/): Always use short hex notation, where available.
* [color-named](http://stylelint.io/user-guide/rules/color-named/): Colors must never be named.
* [color-no-invalid-hex](http://stylelint.io/user-guide/rules/color-no-invalid-hex/): Hex values must be valid.
#### Comment
* [comment-empty-line-before](http://stylelint.io/user-guide/rules/comment-empty-line-before/): There must always be an empty line before comments. _Except_: Comments that are nested and the first child of their parent node. _Ignore_: stylelint commands
* [comment-whitespace-inside](http://stylelint.io/user-guide/rules/comment-whitespace-inside/): There must always be whitespace inside the markers.
#### Declaration
* [declaration-bang-space-after](http://stylelint.io/user-guide/rules/declaration-bang-space-after/): There must never be whitespace after the bang.
* [declaration-bang-space-before](http://stylelint.io/user-guide/rules/declaration-bang-space-before/): There must always be a single space before the bang.
#### Declaration block
* [declaration-block-no-duplicate-properties](http://stylelint.io/user-guide/rules/declaration-block-no-duplicate-properties/): Disallow duplicate properties within declaration blocks. _Ignore_: consecutive duplicated properties.
* [declaration-block-no-shorthand-property-overrides](http://stylelint.io/user-guide/rules/declaration-block-no-shorthand-property-overrides/): Disallow shorthand properties that override related longhand properties.
* [declaration-block-properties-order](http://stylelint.io/user-guide/rules/declaration-block-properties-order/): Properties in declaration blocks must be [sorted according to this list]().
## License
[MIT](./LICENSE) © [GitHub](https://github.com/)

103
__tests__/index.js Normal file
View File

@ -0,0 +1,103 @@
import config from "../"
import stylelint from "stylelint"
import test from "ava"
const validCss = (
`@import "x.css";
@import "y.css";
/**
* Multi-line comment
*/
.selector-1,
.selector-2,
.selector-3[type="text"] {
display: block;
box-sizing: border-box;
color: #333;
background: linear-gradient(#fff, rgba(0, 0, 0, 0.8));
}
.selector-a,
.selector-b:not(:first-child) {
top: calc(calc(1em * 2) / 3);
padding: 10px !important;
}
.selector-x { width: 10%; }
.selector-y { width: 20%; }
.selector-z { width: 30%; }
/* Single-line comment */
@media (min-width >= 60em) {
.selector {
/* Flush to parent comment */
transform: translate(1, 1) scale(3);
}
}
@media (min-orientation: portrait), projection and (color) {
.selector-i + .selector-ii {
font-family: helvetica, "arial black", sans-serif;
background: color(rgb(0, 0, 0) lightness(50%));
}
}
/* Flush single line comment */
@media
screen and (min-resolution: 192dpi),
screen and (min-resolution: 2dppx) {
.selector {
height: 10rem;
margin: 10px;
margin-bottom: 5px;
background-image:
repeating-linear-gradient(
-45deg,
transparent,
#fff 25px,
rgba(255, 255, 255, 1) 50px
);
box-shadow:
0 1px 1px #000,
0 1px 0 #fff,
2px 2px 1px 1px #ccc inset;
}
/* Flush nested single line comment */
.selector::after {
content: "→";
background-image: url("x.svg");
}
}
`)
const invalidCss = (
`a {
top: .2em;
}
`)
test("no warnings with valid css", t => {
return stylelint.lint({
code: validCss,
config: config,
})
.then(data => {
const { errored, results } = data
const { warnings } = results[0]
t.falsy(errored, "no errored")
t.is(warnings.length, 0, "flags no warnings")
})
})
test("a warning with invalid css", t => {
return stylelint.lint({
code: invalidCss,
config: config,
})
.then(data => {
const { errored, results } = data
const { warnings } = results[0]
t.truthy(errored, "errored")
t.is(warnings.length, 1, "flags one warning")
t.is(warnings[0].text, "Expected a leading zero (number-leading-zero)", "correct warning text")
})
})

319
index.js Normal file
View File

@ -0,0 +1,319 @@
module.exports = {
"plugins": [
"stylelint-scss",
"stylelint-selector-no-utility"
],
"rules": {
"at-rule-blacklist": ["extend"],
"at-rule-name-case": "lower",
"at-rule-name-space-after": "always-single-line",
"at-rule-semicolon-newline-after": "always",
"block-closing-brace-newline-after": "always",
"block-closing-brace-newline-before": "always-multi-line",
"block-closing-brace-space-before": "always-single-line",
"block-no-empty": true,
"block-opening-brace-newline-after": "always-multi-line",
"block-opening-brace-space-after": "always-single-line",
"block-opening-brace-space-before": "always",
"color-hex-case": "lower",
"color-hex-length": "short",
"color-named": "never",
"color-no-invalid-hex": true,
"comment-empty-line-before": [
"always",
{
"except": [
"first-nested"
],
"ignore": [
"stylelint-commands"
]
}
],
"comment-whitespace-inside": "always",
"declaration-bang-space-after": "never",
"declaration-bang-space-before": "always",
"declaration-block-no-duplicate-properties": [
true,
{
"ignore": [
"consecutive-duplicates"
]
}
],
"declaration-block-no-shorthand-property-overrides": true,
"declaration-block-properties-order": [
"position",
"top",
"right",
"bottom",
"left",
"z-index",
"display",
"float",
"width",
"min-width",
"max-width",
"height",
"min-height",
"max-height",
"box-sizing",
"padding",
"padding-top",
"padding-right",
"padding-bottom",
"padding-left",
"margin",
"margin-top",
"margin-right",
"margin-bottom",
"margin-left",
"overflow",
"overflow-x",
"overflow-y",
"clip",
"clear",
"font",
"font-family",
"font-size",
"font-style",
"font-weight",
"font-variant",
"font-size-adjust",
"font-stretch",
"font-effect",
"font-emphasize",
"font-emphasize-position",
"font-emphasize-style",
"font-smooth",
"hyphens",
"line-height",
"color",
"text-align",
"text-align-last",
"text-emphasis",
"text-emphasis-color",
"text-emphasis-style",
"text-emphasis-position",
"text-decoration",
"text-indent",
"text-justify",
"text-outline",
"text-overflow",
"text-overflow-ellipsis",
"text-overflow-mode",
"text-shadow",
"text-transform",
"text-wrap",
"letter-spacing",
"word-break",
"word-spacing",
"word-wrap",
"tab-size",
"white-space",
"vertical-align",
"list-style",
"list-style-position",
"list-style-type",
"list-style-image",
"pointer-events",
"fill",
"fill-opacity",
"stroke",
"stroke-opacity",
"stroke-width",
"shape-rendering",
"cursor",
"visibility",
"zoom",
"flex-direction",
"flex-order",
"flex-pack",
"flex-align",
"table-layout",
"empty-cells",
"caption-side",
"border-spacing",
"border-collapse",
"content",
"quotes",
"counter-reset",
"counter-increment",
"resize",
"user-select",
"nav-index",
"nav-up",
"nav-right",
"nav-down",
"nav-left",
"background",
"background-color",
"background-image",
"filter",
"background-repeat",
"background-attachment",
"background-position",
"background-position-x",
"background-position-y",
"background-clip",
"background-origin",
"background-size",
"border",
"border-color",
"border-style",
"border-width",
"border-top",
"border-top-color",
"border-top-style",
"border-top-width",
"border-right",
"border-right-color",
"border-right-style",
"border-right-width",
"border-bottom",
"border-bottom-color",
"border-bottom-style",
"border-bottom-width",
"border-left",
"border-left-color",
"border-left-style",
"border-left-width",
"border-radius",
"border-top-left-radius",
"border-top-right-radius",
"border-bottom-right-radius",
"border-bottom-left-radius",
"border-image",
"border-image-source",
"border-image-slice",
"border-image-width",
"border-image-outset",
"border-image-repeat",
"outline",
"outline-width",
"outline-style",
"outline-color",
"outline-offset",
"box-shadow",
"opacity",
"transition",
"transition-delay",
"transition-timing-function",
"transition-duration",
"transition-property",
"transform",
"transform-origin",
"animation",
"animation-name",
"animation-duration",
"animation-fill-mode",
"animation-play-state",
"animation-timing-function",
"animation-delay",
"animation-iteration-count",
"animation-direction"
],
"declaration-block-semicolon-newline-after": "always",
"declaration-block-semicolon-space-before": "never",
"declaration-block-single-line-max-declarations": 1,
"declaration-block-trailing-semicolon": "always",
"declaration-colon-newline-after": "always-multi-line",
"declaration-colon-space-after": "always-single-line",
"declaration-colon-space-before": "never",
"font-family-name-quotes": "always-where-recommended",
"function-calc-no-unspaced-operator": true,
"function-comma-newline-after": "always-multi-line",
"function-comma-space-after": "always-single-line",
"function-comma-space-before": "never",
"function-linear-gradient-no-nonstandard-direction": true,
"function-max-empty-lines": 0,
"function-name-case": "lower",
"function-parentheses-newline-inside": "always-multi-line",
"function-parentheses-space-inside": "never-single-line",
"function-url-quotes": "always",
"function-whitespace-after": "always",
"indentation": 2,
"max-empty-lines": 1,
"max-nesting-depth": 3,
"media-feature-colon-space-after": "always",
"media-feature-colon-space-before": "never",
"media-feature-no-missing-punctuation": true,
"media-feature-range-operator-space-after": "always",
"media-feature-range-operator-space-before": "always",
"media-query-list-comma-newline-after": "always-multi-line",
"media-query-list-comma-space-after": "always-single-line",
"media-query-list-comma-space-before": "never",
"media-query-parentheses-space-inside": "never",
"no-duplicate-selectors": true,
"no-eol-whitespace": true,
"no-extra-semicolons": true,
"no-invalid-double-slash-comments": true,
"no-missing-eof-newline": true,
"number-leading-zero": "always",
"number-no-trailing-zeros": true,
"number-zero-length-no-unit": true,
"primer/selector-no-utility": true,
"property-case": "lower",
"property-no-vendor-prefix": true,
"property-value-blacklist": {
"/^transition/": [
"/all/"
],
"/^background/": [
"/http:/"
],
"/^border/": [
"none"
],
"/.+/": [
"initial"
]
},
"rule-nested-empty-line-before": [
"always-multi-line",
{
"except": [
"first-nested"
],
"ignore": [
"after-comment"
]
}
],
"scss/at-extend-no-missing-placeholder": true,
"scss/selector-no-redundant-nesting-selector": true,
"selector-attribute-brackets-space-inside": "never",
"selector-attribute-operator-space-after": "never",
"selector-attribute-operator-space-before": "never",
"selector-class-pattern": [
"^(?!(js\\-))[a-z\\-0-9]+$",
{
"message": "Selector should be written in lowercase with hyphens (selector-class-pattern)"
}
],
"selector-combinator-space-after": "always",
"selector-combinator-space-before": "always",
"selector-list-comma-newline-after": "always",
"selector-list-comma-space-before": "never",
"selector-max-compound-selectors": 3,
"selector-max-empty-lines": 0,
"selector-max-specificity": "0,4,0",
"selector-no-id": true,
"selector-no-qualifying-type": true,
"selector-pseudo-class-case": "lower",
"selector-pseudo-class-parentheses-space-inside": "never",
"selector-pseudo-element-case": "lower",
"selector-pseudo-element-colon-notation": "double",
"selector-pseudo-element-no-unknown": true,
"selector-type-case": "lower",
"shorthand-property-no-redundant-values": true,
"string-no-newline": true,
"string-quotes": "double",
"unit-case": "lower",
"unit-no-unknown": true,
"value-list-comma-newline-after": "always-multi-line",
"value-list-comma-space-after": "always-single-line",
"value-list-comma-space-before": "never",
"value-no-vendor-prefix": true
}
}

35
package.json Normal file
View File

@ -0,0 +1,35 @@
{
"name": "stylelint-config-primer",
"version": "1.0.0",
"description": "Sharable stylelint config used by GitHub's CSS",
"main": "index.js",
"scripts": {
"ava": "ava --verbose \"__tests__/**/*.js\"",
"test": "npm run ava"
},
"repository": {
"type": "git",
"url": "git+https://github.com/primer/stylelint-config-primer.git"
},
"keywords": [
"github",
"primer",
"stylelint-config",
"stylelint",
"css"
],
"author": "GitHub, Inc.",
"license": "MIT",
"bugs": {
"url": "https://github.com/primer/stylelint-config-primer/issues"
},
"homepage": "https://github.com/primer/stylelint-config-primer#readme",
"dependencies": {
"stylelint-scss": "^1.1.1",
"stylelint-selector-no-utility": "^1.1.0"
},
"devDependencies": {
"ava": "^0.15.2",
"stylelint": "^6.6.0"
}
}