Initial commit

This commit is contained in:
Patrick Marsceill
2017-03-09 13:16:08 -05:00
commit b7b0d0d7bf
4147 changed files with 401224 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
# no-unsupported-browser-features
***Deprecated: See [CHANGELOG](../../../CHANGELOG.md).***
Disallow features that are unsupported by the browsers that you are targeting.
```css
.foo { opacity: 1; }
/** ↑
* Features like this, which is unsupported in IE 8 */
```
This rule uses [doiuse](https://github.com/anandthakker/doiuse) to detect browser support. doiuse itself checks your code against the ["Can I use"](http://caniuse.com/) database.
**This is a good rule to use with "warning"-level severity**, because its primary purpose is to warn you that you are using features not all browsers fully support *and therefore ought to provide fallbacks*. But the warning will continue even if you have a fallback in place (it doesn't know); so you probably do not want this rule to break your build. Instead, consider it a friendly reminder to double-check certain spots for fallbacks.
Bugs and feature requests should be reported on the [doiuse issue tracker](https://github.com/anandthakker/doiuse/issues).
## Options
### `true`
Defaults to the doiuse default, which is `"> 1%, last 2 versions, Firefox ESR, Opera 12.1"`.
The following patterns are considered warnings:
```css
a { opacity: 0.5; }
```
As IE8 (which as of this writing had *just over* 1% global usage) does not support `opacity`:
## Optional secondary options
These options are passed directly to doiuse.
### `browsers: "browserslist string"`
A string interpreted by [browserslist](https://github.com/ai/browserslist) that designates precisely which browsers you wish to support. Something like `"> 1%, last 2 versions, ie >= 8"`. For details about the syntax (which is the same as when using Autoprefixer, by the way), please read [the browserslist documentation](https://github.com/ai/browserslist).
If you set `browsers: "last 2 versions, ie >=9"` the declaration above is allowed.
### `ignore: [ "array", "of", "features", "to", "ignore" ]`
If you no longer want to be warned about, say, your use of `rem`, you can use `ignore: ["rem"]`.

View File

@@ -0,0 +1,80 @@
"use strict"
const doiuse = require("doiuse")
const report = require("../../utils/report")
const ruleMessages = require("../../utils/ruleMessages")
const validateOptions = require("../../utils/validateOptions")
const Result = require("postcss/lib/result")
const _ = require("lodash")
const ruleName = "no-unsupported-browser-features"
const messages = ruleMessages(ruleName, {
rejected: details => `Unexpected browser feature ${details}`,
})
const rule = function (on, options) {
return (root, result) => {
const validOptions = validateOptions(result, ruleName, { actual: on }, {
optional: true,
actual: options,
possible: {
browsers: [_.isString],
ignore: [_.isString],
},
})
if (!validOptions) {
return
}
result.warn((
`'${ruleName}' has been deprecated and in 8.0 will be removed.`
), {
stylelintType: "deprecation",
stylelintReference: `https://stylelint.io/user-guide/rules/${ruleName}/`,
})
const doiuseOptions = {}
if (options && options.browsers) {
doiuseOptions.browsers = options.browsers
}
if (options && options.ignore) {
doiuseOptions.ignore = options.ignore
}
const doiuseResult = new Result()
doiuse(doiuseOptions).postcss(root, doiuseResult)
doiuseResult.warnings().forEach(doiuseWarning => {
report({
ruleName,
result,
message: messages.rejected(cleanDoiuseWarningText(doiuseWarning.text)),
node: doiuseWarning.node,
line: doiuseWarning.line,
column: doiuseWarning.column,
})
})
}
}
function cleanDoiuseWarningText(warningText) {
// Get index of feature Id
const featureIdIndex = warningText.lastIndexOf("(")
// Get feature Id, then replace brackets with quotes
const featureId = warningText.slice(featureIdIndex, warningText.length).replace(/\(|\)/g, "\"")
// Get start of support text i.e. "x not supported by...", or "y only partially supported by..."
const browserSupportStartIndex = warningText.indexOf("not") !== -1 ? warningText.indexOf("not") : warningText.indexOf("only")
// Get browser support text, then strip brackets.
const browserSupport = warningText.slice(browserSupportStartIndex, featureIdIndex - 1).replace(/\(|\)|:/g, "")
return `${featureId} is ${browserSupport}`
}
rule.ruleName = ruleName
rule.messages = messages
module.exports = rule