eslint-plugin-sort-class-members
Advanced tools
Comparing version 1.11.0 to 1.12.0
@@ -8,3 +8,3 @@ "use strict"; | ||
rules: { | ||
'sort-class-members': _sortClassMembers.sortClassMembers.getRule() | ||
'sort-class-members': _sortClassMembers.sortClassMembersRule | ||
}, | ||
@@ -11,0 +11,0 @@ configs: { |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.sortClassMembers = void 0; | ||
exports.sortClassMembersRule = void 0; | ||
@@ -15,3 +15,3 @@ var _schema = require("./schema"); | ||
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); } | ||
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } | ||
@@ -24,13 +24,13 @@ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } | ||
function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } | ||
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
function _createForOfIteratorHelper(o) { if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (o = _unsupportedIterableToArray(o))) { var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var it, normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } | ||
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(n); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; } | ||
@@ -41,98 +41,101 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
var sortClassMembers = { | ||
getRule: function getRule() { | ||
var defaults = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var sortClassMembersRule = { | ||
meta: { | ||
type: 'suggestion', | ||
docs: { | ||
description: 'Enforce consistent members order', | ||
category: 'Possible Errors', | ||
recommended: false, | ||
url: 'https://github.com/bryanrsmith/eslint-plugin-sort-class-members' | ||
}, | ||
fixable: 'code', | ||
schema: _schema.sortClassMembersSchema | ||
}, | ||
create: function sortClassMembersRule(context) { | ||
var options = context.options[0] || {}; | ||
var stopAfterFirst = !!options.stopAfterFirstProblem; | ||
var accessorPairPositioning = options.accessorPairPositioning || 'getThenSet'; | ||
var order = options.order || []; | ||
function sortClassMembersRule(context) { | ||
var options = context.options[0] || {}; | ||
var stopAfterFirst = !!options.stopAfterFirstProblem; | ||
var accessorPairPositioning = options.accessorPairPositioning || 'getThenSet'; | ||
var order = options.order || defaults.order || []; | ||
var groups = _objectSpread(_objectSpread({}, builtInGroups), options.groups); | ||
var groups = _objectSpread({}, builtInGroups, {}, defaults.groups, {}, options.groups); | ||
var orderedSlots = getExpectedOrder(order, groups); | ||
var groupAccessors = accessorPairPositioning !== 'any'; | ||
var locale = options.locale || 'en-US'; | ||
var rules = { | ||
ClassDeclaration: function ClassDeclaration(node) { | ||
var members = getClassMemberInfos(node, context.getSourceCode(), orderedSlots); // check for out-of-order and separated get/set pairs | ||
var orderedSlots = getExpectedOrder(order, groups); | ||
var groupAccessors = accessorPairPositioning !== 'any'; | ||
var locale = options.locale || 'en-US'; | ||
var rules = { | ||
ClassDeclaration: function ClassDeclaration(node) { | ||
var members = getClassMemberInfos(node, context.getSourceCode(), orderedSlots); // check for out-of-order and separated get/set pairs | ||
var accessorPairProblems = findAccessorPairProblems(members, accessorPairPositioning); | ||
var accessorPairProblems = findAccessorPairProblems(members, accessorPairPositioning); | ||
var _iterator = _createForOfIteratorHelper(accessorPairProblems), | ||
_step; | ||
var _iterator = _createForOfIteratorHelper(accessorPairProblems), | ||
_step; | ||
try { | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var problem = _step.value; | ||
var message = 'Expected {{ source }} to come immediately {{ expected }} {{ target }}.'; | ||
reportProblem({ | ||
problem: problem, | ||
context: context, | ||
message: message, | ||
stopAfterFirst: stopAfterFirst, | ||
problemCount: problemCount | ||
}); | ||
try { | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var problem = _step.value; | ||
var message = 'Expected {{ source }} to come immediately {{ expected }} {{ target }}.'; | ||
reportProblem({ | ||
problem: problem, | ||
context: context, | ||
message: message, | ||
stopAfterFirst: stopAfterFirst, | ||
problemCount: problemCount | ||
}); | ||
if (stopAfterFirst) { | ||
break; | ||
} | ||
} // filter out the second accessor in each pair so we only detect one problem | ||
// for out-of-order accessor pairs | ||
if (stopAfterFirst) { | ||
break; | ||
} | ||
} // filter out the second accessor in each pair so we only detect one problem | ||
// for out-of-order accessor pairs | ||
} catch (err) { | ||
_iterator.e(err); | ||
} finally { | ||
_iterator.f(); | ||
} | ||
} catch (err) { | ||
_iterator.e(err); | ||
} finally { | ||
_iterator.f(); | ||
} | ||
members = members.filter(function (m) { | ||
return !(m.matchingAccessor && !m.isFirstAccessor); | ||
}); // ignore members that don't match any slots | ||
members = members.filter(function (m) { | ||
return !(m.matchingAccessor && !m.isFirstAccessor); | ||
}); // ignore members that don't match any slots | ||
members = members.filter(function (member) { | ||
return member.acceptableSlots.length; | ||
}); // check member positions against rule order | ||
members = members.filter(function (member) { | ||
return member.acceptableSlots.length; | ||
}); // check member positions against rule order | ||
var problems = findProblems(members, locale); | ||
var problemCount = problems.length; | ||
var problems = findProblems(members, locale); | ||
var problemCount = problems.length; | ||
var _iterator2 = _createForOfIteratorHelper(problems), | ||
_step2; | ||
var _iterator2 = _createForOfIteratorHelper(problems), | ||
_step2; | ||
try { | ||
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { | ||
var _problem = _step2.value; | ||
var _message = 'Expected {{ source }} to come {{ expected }} {{ target }}.'; | ||
reportProblem({ | ||
problem: _problem, | ||
message: _message, | ||
context: context, | ||
stopAfterFirst: stopAfterFirst, | ||
problemCount: problemCount, | ||
groupAccessors: groupAccessors | ||
}); | ||
try { | ||
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { | ||
var _problem = _step2.value; | ||
var _message = 'Expected {{ source }} to come {{ expected }} {{ target }}.'; | ||
reportProblem({ | ||
problem: _problem, | ||
message: _message, | ||
context: context, | ||
stopAfterFirst: stopAfterFirst, | ||
problemCount: problemCount, | ||
groupAccessors: groupAccessors | ||
}); | ||
if (stopAfterFirst) { | ||
break; | ||
} | ||
if (stopAfterFirst) { | ||
break; | ||
} | ||
} catch (err) { | ||
_iterator2.e(err); | ||
} finally { | ||
_iterator2.f(); | ||
} | ||
} catch (err) { | ||
_iterator2.e(err); | ||
} finally { | ||
_iterator2.f(); | ||
} | ||
}; | ||
rules.ClassExpression = rules.ClassDeclaration; | ||
return rules; | ||
} | ||
sortClassMembersRule.schema = _schema.sortClassMembersSchema; | ||
sortClassMembersRule.fixable = 'code'; | ||
return sortClassMembersRule; | ||
} | ||
}; | ||
rules.ClassExpression = rules.ClassDeclaration; | ||
return rules; | ||
} | ||
}; | ||
exports.sortClassMembers = sortClassMembers; | ||
exports.sortClassMembersRule = sortClassMembersRule; | ||
@@ -229,3 +232,3 @@ function reportProblem(_ref) { | ||
var members = classMemberNodes.map(function (member, i) { | ||
return _objectSpread({}, getMemberInfo(member, sourceCode), { | ||
return _objectSpread(_objectSpread({}, getMemberInfo(member, sourceCode)), {}, { | ||
id: String(i) | ||
@@ -236,3 +239,3 @@ }); | ||
var acceptableSlots = getAcceptableSlots(memberInfo, orderedSlots); | ||
return _objectSpread({}, memberInfo, { | ||
return _objectSpread(_objectSpread({}, memberInfo), {}, { | ||
acceptableSlots: acceptableSlots | ||
@@ -239,0 +242,0 @@ }); |
{ | ||
"name": "eslint-plugin-sort-class-members", | ||
"version": "1.11.0", | ||
"version": "1.12.0", | ||
"description": "ESLint rule for enforcing consistent ES6 class member order.", | ||
@@ -42,9 +42,11 @@ "keywords": [ | ||
"@babel/cli": "^7.8.4", | ||
"@babel/eslint-parser": "^7.15.8", | ||
"@babel/plugin-proposal-class-properties": "^7.14.5", | ||
"@babel/plugin-proposal-decorators": "^7.15.8", | ||
"@babel/preset-env": "^7.9.5", | ||
"@babel/register": "^7.9.0", | ||
"@bryanrsmith/eslint-config-standard": "^2.1.3", | ||
"babel-eslint": "^10.1.0", | ||
"babel-plugin-istanbul": "^6.0.0", | ||
"coveralls": "^2.11.9", | ||
"eslint": "^6.8.0", | ||
"eslint": "^8.0.0", | ||
"eslint-config-prettier": "^6.10.1", | ||
@@ -51,0 +53,0 @@ "mocha": "^7.1.1", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
30737
606
15