Skip to content

Commit

Permalink
Move to es6
Browse files Browse the repository at this point in the history
  • Loading branch information
ismay committed Feb 1, 2018
1 parent e62f917 commit fd47d7c
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 111 deletions.
5 changes: 1 addition & 4 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
{
"extends": ["airbnb-base/legacy", "prettier"],
"extends": ["airbnb-base", "prettier"],
"env": {
"node": true
},
"rules": {
"func-names": 0
}
}
42 changes: 20 additions & 22 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
var _ = require('lodash');
var stylelint = require('stylelint');
var doiuse = require('doiuse');
var Result = require('postcss/lib/result');
const _ = require('lodash');
const stylelint = require('stylelint');
const doiuse = require('doiuse');
const 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;
}
const ruleName = 'plugin/no-unsupported-browser-features';
const messages = stylelint.utils.ruleMessages(ruleName, {
rejected: details => `Unexpected browser feature ${details}`
});

/**
* Options
*/

var optionsSchema = {
const optionsSchema = {
browsers: [_.isString],
ignore: [_.isString]
};
Expand All @@ -29,21 +27,21 @@ var optionsSchema = {

function cleanWarningText(warningText) {
// Get index of feature Id
var featureIdIndex = warningText.lastIndexOf('(');
const featureIdIndex = warningText.lastIndexOf('(');

// Get feature Id, then replace brackets with quotes
var featureId = warningText.slice(featureIdIndex, warningText.length).replace(/\(|\)/g, '"');
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..."
var browserSupportStartIndex =
const browserSupportStartIndex =
warningText.indexOf('not') !== -1 ? warningText.indexOf('not') : warningText.indexOf('only');

// Get browser support text, then strip brackets.
var browserSupport = warningText
const browserSupport = warningText
.slice(browserSupportStartIndex, featureIdIndex - 1)
.replace(/\(|\)|:/g, '');

var cleanedWarningText = featureId + ' is ' + browserSupport;
const cleanedWarningText = `${featureId} is ${browserSupport}`;

return cleanedWarningText;
}
Expand All @@ -53,23 +51,23 @@ function cleanWarningText(warningText) {
*/

function ruleFunction(on, options) {
return function postCssPlugin(root, result) {
var validOptions = stylelint.utils.validateOptions(result, ruleName, {
return (root, result) => {
const validOptions = stylelint.utils.validateOptions(result, ruleName, {
actual: options,
possible: optionsSchema,
optional: true
});

var doiuseOptions = _.pick(options, Object.keys(optionsSchema));
var doiuseResult = new Result();
const doiuseOptions = _.pick(options, Object.keys(optionsSchema));
const doiuseResult = new Result();

if (!validOptions) return;

doiuse(doiuseOptions).postcss(root, doiuseResult);
doiuseResult.warnings().forEach(function reportWarning(doiuseWarning) {
doiuseResult.warnings().forEach(doiuseWarning => {
stylelint.utils.report({
ruleName: ruleName,
result: result,
ruleName,
result,
message: messages.rejected(cleanWarningText(doiuseWarning.text)),
node: doiuseWarning.node,
line: doiuseWarning.line,
Expand Down
Loading

0 comments on commit fd47d7c

Please sign in to comment.