-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
492 additions
and
238 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,9 @@ | ||
{ | ||
"extends": ["airbnb-base/legacy", "prettier"], | ||
"env": { | ||
"node": true | ||
}, | ||
"extends": [ | ||
"airbnb-base/legacy" | ||
], | ||
"rules": { | ||
"comma-dangle": [2, "never"], | ||
"func-names": [2, "as-needed"], | ||
"no-warning-comments": [2, { "terms": ["todo", "fixme"], "location": "anywhere" }], | ||
"semi": [2, "never"] | ||
"func-names": 0 | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,6 @@ node_modules | |
npm-debug.log | ||
yarn-error.log | ||
package-lock.json | ||
|
||
# Coveralls coverage | ||
/coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"**/*.js": [ | ||
"prettier --write", | ||
"git add", | ||
"eslint" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Dotfiles | ||
.editorconfig | ||
.eslintrc | ||
.gitattributes | ||
.gitignore | ||
.lintstagedrc | ||
.prettierrc | ||
.travis.yml | ||
|
||
# Tests | ||
/test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"printWidth": 100, | ||
"useTabs": false, | ||
"singleQuote": true, | ||
"tabWidth": 2, | ||
"semi": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`stylelint-no-unsupported-browser-features ignore option should ignore a single property 1`] = ` | ||
Array [ | ||
Object { | ||
"deprecations": Array [], | ||
"invalidOptionWarnings": Array [], | ||
"parseErrors": Array [], | ||
"source": "<input css 5>", | ||
"warnings": Array [], | ||
}, | ||
] | ||
`; | ||
|
||
exports[`stylelint-no-unsupported-browser-features ignore option should ignore multiple properties 1`] = ` | ||
Array [ | ||
Object { | ||
"deprecations": Array [], | ||
"invalidOptionWarnings": Array [], | ||
"parseErrors": Array [], | ||
"source": "<input css 6>", | ||
"warnings": Array [], | ||
}, | ||
] | ||
`; | ||
|
||
exports[`stylelint-no-unsupported-browser-features multiple browsers should allow display:table for IE 8 and IE 9 1`] = ` | ||
Array [ | ||
Object { | ||
"deprecations": Array [], | ||
"invalidOptionWarnings": Array [], | ||
"parseErrors": Array [], | ||
"source": "<input css 3>", | ||
"warnings": Array [], | ||
}, | ||
] | ||
`; | ||
|
||
exports[`stylelint-no-unsupported-browser-features multiple browsers should disallow display:table for IE 6 and IE 7 1`] = ` | ||
Array [ | ||
Object { | ||
"deprecations": Array [], | ||
"errored": true, | ||
"invalidOptionWarnings": Array [], | ||
"parseErrors": Array [], | ||
"source": "<input css 4>", | ||
"warnings": Array [ | ||
Object { | ||
"column": 7, | ||
"line": 1, | ||
"rule": "plugin/no-unsupported-browser-features", | ||
"severity": "error", | ||
"text": "Unexpected browser feature \\"css-table\\" is not supported by IE 6,7 (plugin/no-unsupported-browser-features)", | ||
}, | ||
], | ||
}, | ||
] | ||
`; | ||
|
||
exports[`stylelint-no-unsupported-browser-features single browser should allow display:table for IE 8 1`] = ` | ||
Array [ | ||
Object { | ||
"deprecations": Array [], | ||
"invalidOptionWarnings": Array [], | ||
"parseErrors": Array [], | ||
"source": "<input css 1>", | ||
"warnings": Array [], | ||
}, | ||
] | ||
`; | ||
|
||
exports[`stylelint-no-unsupported-browser-features single browser should disallow display:table for IE 6 1`] = ` | ||
Array [ | ||
Object { | ||
"deprecations": Array [], | ||
"errored": true, | ||
"invalidOptionWarnings": Array [], | ||
"parseErrors": Array [], | ||
"source": "<input css 2>", | ||
"warnings": Array [ | ||
Object { | ||
"column": 7, | ||
"line": 1, | ||
"rule": "plugin/no-unsupported-browser-features", | ||
"severity": "error", | ||
"text": "Unexpected browser feature \\"css-table\\" is not supported by IE 6 (plugin/no-unsupported-browser-features)", | ||
}, | ||
], | ||
}, | ||
] | ||
`; | ||
|
||
exports[`stylelint-no-unsupported-browser-features validate options should validate the browsers option 1`] = ` | ||
Array [ | ||
Object { | ||
"deprecations": Array [], | ||
"errored": true, | ||
"invalidOptionWarnings": Array [ | ||
Object { | ||
"text": "Invalid value \\"1\\" for option \\"browsers\\" of rule \\"plugin/no-unsupported-browser-features\\"", | ||
}, | ||
], | ||
"parseErrors": Array [], | ||
"source": "<input css 7>", | ||
"warnings": Array [], | ||
}, | ||
] | ||
`; | ||
|
||
exports[`stylelint-no-unsupported-browser-features validate options should validate the ignore option 1`] = ` | ||
Array [ | ||
Object { | ||
"deprecations": Array [], | ||
"errored": true, | ||
"invalidOptionWarnings": Array [ | ||
Object { | ||
"text": "Invalid value \\"1\\" for option \\"ignore\\" of rule \\"plugin/no-unsupported-browser-features\\"", | ||
}, | ||
], | ||
"parseErrors": Array [], | ||
"source": "<input css 8>", | ||
"warnings": Array [], | ||
}, | ||
] | ||
`; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
var _ = require('lodash'); | ||
var stylelint = require('stylelint'); | ||
var doiuse = require('doiuse'); | ||
var Result = require('postcss/lib/result'); | ||
|
||
/** | ||
* Plugin settings | ||
*/ | ||
|
||
var ruleName = 'plugin/no-unsupported-browser-features'; | ||
var messages = stylelint.utils.ruleMessages(ruleName, { | ||
rejected: function rejectRule(details) { | ||
return 'Unexpected browser feature ' + details; | ||
} | ||
}); | ||
|
||
/** | ||
* The allowed options | ||
*/ | ||
|
||
var optionsSchema = { | ||
browsers: [_.isString], | ||
ignore: [_.isString] | ||
}; | ||
|
||
/** | ||
* Utilities | ||
*/ | ||
|
||
function cleanWarningText(warningText) { | ||
// Get index of feature Id | ||
var featureIdIndex = warningText.lastIndexOf('('); | ||
|
||
// Get feature Id, then replace brackets with quotes | ||
var 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..." | ||
var browserSupportStartIndex = | ||
warningText.indexOf('not') !== -1 ? warningText.indexOf('not') : warningText.indexOf('only'); | ||
|
||
// Get browser support text, then strip brackets. | ||
var browserSupport = warningText | ||
.slice(browserSupportStartIndex, featureIdIndex - 1) | ||
.replace(/\(|\)|:/g, ''); | ||
|
||
var cleanedWarningText = featureId + ' is ' + browserSupport; | ||
|
||
return cleanedWarningText; | ||
} | ||
|
||
function parseOptions(options) { | ||
var doiuseOptions = {}; | ||
|
||
if (options && options.browsers) { | ||
doiuseOptions.browsers = options.browsers; | ||
} | ||
|
||
if (options && options.ignore) { | ||
doiuseOptions.ignore = options.ignore; | ||
} | ||
|
||
return doiuseOptions; | ||
} | ||
|
||
/** | ||
* The main plugin rule | ||
*/ | ||
|
||
function ruleFunction(on, options) { | ||
return function postCssPlugin(root, result) { | ||
var validOptions = stylelint.utils.validateOptions(result, ruleName, { | ||
actual: options, | ||
possible: optionsSchema, | ||
optional: true | ||
}); | ||
|
||
var doiuseOptions = parseOptions(options); | ||
var doiuseResult = new Result(); | ||
|
||
if (!validOptions) return; | ||
|
||
doiuse(doiuseOptions).postcss(root, doiuseResult); | ||
doiuseResult.warnings().forEach(function reportWarning(doiuseWarning) { | ||
stylelint.utils.report({ | ||
ruleName: ruleName, | ||
result: result, | ||
message: messages.rejected(cleanWarningText(doiuseWarning.text)), | ||
node: doiuseWarning.node, | ||
line: doiuseWarning.line, | ||
column: doiuseWarning.column | ||
}); | ||
}); | ||
}; | ||
} | ||
|
||
module.exports = stylelint.createPlugin(ruleName, ruleFunction); | ||
module.exports.ruleName = ruleName; | ||
module.exports.messages = messages; |
Oops, something went wrong.