From 8d525833c3166ba5f453050adf130252db82e863 Mon Sep 17 00:00:00 2001 From: Konstantin Date: Thu, 23 Mar 2017 17:58:02 +0500 Subject: [PATCH] Fuck npm MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Я вообще не понимаю как публиковать --- .gitignore | 1 - dist/index.js | 148 ++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 2 +- 3 files changed, 149 insertions(+), 2 deletions(-) create mode 100644 dist/index.js diff --git a/.gitignore b/.gitignore index d9d7e40..48745e7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ node_modules -dist *.sublime-project *.sublime-workspace diff --git a/dist/index.js b/dist/index.js new file mode 100644 index 0000000..96d6190 --- /dev/null +++ b/dist/index.js @@ -0,0 +1,148 @@ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.messages = exports.ruleName = undefined; + +var _stylelint = require('stylelint'); + +var _stylelint2 = _interopRequireDefault(_stylelint); + +var _postcssValueParser = require('postcss-value-parser'); + +var _postcssValueParser2 = _interopRequireDefault(_postcssValueParser); + +var _isString = require('lodash/isString'); + +var _isString2 = _interopRequireDefault(_isString); + +var _filter = require('lodash/filter'); + +var _filter2 = _interopRequireDefault(_filter); + +var _declarationValueIndex = require('stylelint/lib/utils/declarationValueIndex'); + +var _declarationValueIndex2 = _interopRequireDefault(_declarationValueIndex); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +var ruleName = exports.ruleName = 'plugin/no-low-performance-animation'; +var messages = exports.messages = _stylelint2.default.utils.ruleMessages(ruleName, { + default: function _default(prop) { + return 'You should not use low performance animation properties (' + prop + ').'; + } +}); + +var TIMING_FUNCTION_KEYWORDS = ['ease', 'ease-in', 'ease-out', 'ease-in-out', 'linear', 'step-start', 'step-end']; + +var optionsSchema = { + ignore: [_isString2.default] +}; + +module.exports = _stylelint2.default.createPlugin(ruleName, function (actual, options) { + return function (cssRoot, result) { + + var validOptions = _stylelint2.default.utils.validateOptions(result, ruleName, { actual: actual }, { + actual: options, + possible: optionsSchema, + optional: true + }); + + if (!validOptions) return; + + var allowedValue = ['opacity', 'transform', 'none', 'initial', 'inherit'].concat(options ? options.ignore : []); + + cssRoot.walkDecls('transition-property', function (decl) { + var value = decl.value; + + (0, _postcssValueParser2.default)(value).walk(function (node) { + if (node.type === 'word' && allowedValue.indexOf(node.value) < 0) { + var index = (0, _declarationValueIndex2.default)(decl) + node.sourceIndex; + _stylelint2.default.utils.report({ + ruleName: ruleName, + result: result, + node: decl, + message: messages.default(node.value), + index: index + }); + } + }); + + return; + }); + + cssRoot.walkDecls('transition', function (decl) { + var value = decl.value; + var nodes = []; + + (0, _postcssValueParser2.default)(value).walk(function (node) { + if (node.type === 'word') nodes.push({ index: node.sourceIndex, value: node.value }); + return false; + }); + + var props = nodes.filter(function (_ref) { + var value = _ref.value; + + if (/[\+-]?[\w\.]*m?s/gim.test(value)) return false; + if (/^\$/gim.test(value)) return false; + if (TIMING_FUNCTION_KEYWORDS.indexOf(value) >= 0) return false; + return true; + }); + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + + try { + for (var _iterator = props[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var prop = _step.value; + + var index = (0, _declarationValueIndex2.default)(decl) + prop.index; + if (allowedValue.indexOf(prop.value) < 0) { + _stylelint2.default.utils.report({ + ruleName: ruleName, + result: result, + node: decl, + message: messages.default(prop.value), + index: index + }); + return; + } + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator.return) { + _iterator.return(); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } + } + } + + return; + }); + + cssRoot.walkAtRules(/^keyframes$/i, function (atRuleKeyframes) { + atRuleKeyframes.walkDecls(function (decl) { + if (allowedValue.indexOf(decl.prop) < 0) { + var index = 1; + _stylelint2.default.utils.report({ + ruleName: ruleName, + result: result, + node: decl, + message: messages.default(decl.prop) + }); + return; + }; + }); + }); + }; +}); + +module.exports.ruleName = ruleName; +module.exports.messages = messages; \ No newline at end of file diff --git a/package.json b/package.json index d87f803..27b3bf3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "stylelint-performance-animation", - "version": "1.2.1", + "version": "1.2.2", "description": "Stylelint rule for preventing the use of low performance animation", "main": "./dist/index.js", "scripts": {