Socket
Socket
Sign inDemoInstall

eslint-plugin-sort-decorators

Package Overview
Dependencies
127
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.0 to 0.2.0

2

dist/index.js

@@ -1,1 +0,1 @@

"use strict";function r(r,e){if(e==null||e>r.length)e=r.length;for(var t=0,n=new Array(e);t<e;t++)n[t]=r[t];return n}function e(r){if(Array.isArray(r))return r}function t(r,e,t){if(e in r){Object.defineProperty(r,e,{value:t,enumerable:true,configurable:true,writable:true})}else{r[e]=t}return r}function n(r){if(typeof Symbol!=="undefined"&&r[Symbol.iterator]!=null||r["@@iterator"]!=null)return Array.from(r)}function o(r,e){var t=r==null?null:typeof Symbol!=="undefined"&&r[Symbol.iterator]||r["@@iterator"];if(t==null)return;var n=[];var o=true;var i=false;var a,c;try{for(t=t.call(r);!(o=(a=t.next()).done);o=true){n.push(a.value);if(e&&n.length===e)break}}catch(r){i=true;c=r}finally{try{if(!o&&t["return"]!=null)t["return"]()}finally{if(i)throw c}}return n}function i(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function a(r){for(var e=1;e<arguments.length;e++){var n=arguments[e]!=null?arguments[e]:{};var o=Object.keys(n);if(typeof Object.getOwnPropertySymbols==="function"){o=o.concat(Object.getOwnPropertySymbols(n).filter(function(r){return Object.getOwnPropertyDescriptor(n,r).enumerable}))}o.forEach(function(e){t(r,e,n[e])})}return r}function c(r,e){var t=Object.keys(r);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(r);if(e){n=n.filter(function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable})}t.push.apply(t,n)}return t}function u(r,e){e=e!=null?e:{};if(Object.getOwnPropertyDescriptors){Object.defineProperties(r,Object.getOwnPropertyDescriptors(e))}else{c(Object(e)).forEach(function(t){Object.defineProperty(r,t,Object.getOwnPropertyDescriptor(e,t))})}return r}function s(r,t){return e(r)||o(r,t)||d(r,t)||i()}function f(r){return e(r)||n(r)||d(r)||i()}function d(e,t){if(!e)return;if(typeof e==="string")return r(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if(n==="Object"&&e.constructor)n=e.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 r(e,t)}var l=require("@typescript-eslint/types");var v=require("@typescript-eslint/utils");var p={$schema:"http://json-schema.org/draft-07/schema#",additionalProperties:!1,properties:{autoFix:{default:!1,description:"Automatically fix the order.\nWhen set to `true`, only one error is reported and the whole set of decorators is fixed.",type:"boolean"},caseSensitive:{default:!0,description:"If true, enforce properties to be in case-sensitive order.",type:"boolean"},direction:{description:"Specify the direction of the ordering.",enum:["asc","desc"],type:"string"}},type:"object"};var y=v.ESLintUtils.RuleCreator(function(r){return r});function m(r){return y(u(a({},r),{defaultOptions:[{autoFix:!1,caseSensitive:!0,direction:"asc"}],meta:u(a({schema:[p]},r.meta),{docs:u(a({requiresTypeChecking:!1},r.meta.docs),{recommended:"warn"}),fixable:"code",messages:{"incorrect-order":"Expected decorators to be in sorted order. `@{{ after }}` should be before `@{{ previous }}`."},type:"layout"})}))}function b(r){var e=function(r){switch(r.type){case v.AST_NODE_TYPES.CallExpression:return e(r.callee);case v.AST_NODE_TYPES.Identifier:return r.name}throw new Error("Not a valid decorator.")};return e(r.expression)}function h(r,e,t){var n=t.autoFix,o=t.caseSensitive,i=t.direction,a=function(r){var e=b(r);return o?e:e.toLowerCase()},c=function(r,e){var t;return t=s(i==="desc"?[e,r]:[r,e],2),r=t[0],e=t[1],t,r===e?0:r<e?-1:1},u=e.map(function(r){return{name:a(r),node:r}}),d=function(e,t){var n=r.getSourceCode(),o=n.getText(),i=t.slice().sort(function(r,e){var t=r.name,n=e.name;return c(t,n)}).map(function(r){var e=r.node;return e}),a=i.map(function(r,e){var a=e===i.length-1?"":o.slice(t[e].node.range[1],t[e+1].node.range[0]);return n.getText(r)+a});return e.replaceTextRange([t[0].node.range[0],t[t.length-1].node.range[1]],a.join(""))},l=function(e){if(e.length<=1)return;var t=f(e),o=t[0],i=o.name,a=t.slice(1);var u=true,s=false,v=undefined;try{for(var p=a[Symbol.iterator](),y;!(u=(y=p.next()).done);u=true){var m=y.value,b=m.name,h=m.node;if(c(i,b)>0){r.report({data:{after:b,previous:i},fix:n?function(r){return d(r,e)}:void 0,messageId:"incorrect-order",node:h});return}}}catch(r){s=true;v=r}finally{try{if(!u&&p.return!=null){p.return()}}finally{if(s){throw v}}}n&&l(e.slice(1))};l(u)}var g="sort-on-accessors",O=m({create:function(r,e){var t=s(e,1),n=t[0];var o=n.autoFix,i=function(r){var e;var t=r.parent;return((e=t)===null||e===void 0?void 0:e.type)===l.AST_NODE_TYPES.MethodDefinition&&t.kind==="get"?t:!1};return o?{Decorator:function e(e){var t=i(e);if(!t)return;var o=t.decorators;o[0]===e&&h(r,o,n)}}:{Decorator:function e(e){var t=i(e);if(!t)return;var o=t.decorators,a=o.findIndex(function(r){return r===e});h(r,o.slice(a),n)}}},meta:{docs:{description:"Enforces order of accessors decorators"}},name:g});var S="sort-on-classes",E=m({create:function(r,e){var t=s(e,1),n=t[0];var o=n.autoFix;return o?{ClassDeclaration:function e(e){var t=e.decorators;h(r,t!==null&&t!==void 0?t:[],n)}}:{Decorator:function e(e){var t;var o=e.parent;if(((t=o)===null||t===void 0?void 0:t.type)!==l.AST_NODE_TYPES.ClassDeclaration)return;var i=o.decorators,a=i.findIndex(function(r){return r===e});h(r,i.slice(a),n)}}},meta:{docs:{description:"Enforces order of class decorators"}},name:S});var x="sort-on-methods",D=m({create:function(r,e){var t=s(e,1),n=t[0];var o=n.autoFix;return o?{MethodDefinition:function e(e){var t=e.decorators,o=e.kind;o==="method"&&h(r,t,n)}}:{Decorator:function e(e){var t;var o=e.parent;if(((t=o)===null||t===void 0?void 0:t.type)!==l.AST_NODE_TYPES.MethodDefinition)return;var i=o.decorators,a=i.findIndex(function(r){return r===e});h(r,i.slice(a),n)}}},meta:{docs:{description:"Enforces order of methods decorators"}},name:x});var P="sort-on-parameters",j=m({create:function(r,e){var t=s(e,1),n=t[0];var o=n.autoFix,i=function(r){var e,t;var n=r.parent;return((e=n)===null||e===void 0?void 0:e.type)===l.AST_NODE_TYPES.Identifier&&((t=n.parent)===null||t===void 0?void 0:t.type)===l.AST_NODE_TYPES.FunctionExpression?n:!1};return o?{Decorator:function e(e){var t=i(e);if(!t)return;var o=t.decorators;o[0]===e&&h(r,o,n)}}:{Decorator:function e(e){var t=i(e);if(!t)return;var o=t.decorators,a=o.findIndex(function(r){return r===e});h(r,o.slice(a),n)}}},meta:{docs:{description:"Enforces order of parameters decorators"}},name:P});var w="sort-on-properties",T=m({create:function(r,e){var t=s(e,1),n=t[0];var o=n.autoFix;return o?{PropertyDefinition:function e(e){var t=e.decorators;h(r,t!==null&&t!==void 0?t:[],n)}}:{Decorator:function e(e){var t;var o=e.parent;if(((t=o)===null||t===void 0?void 0:t.type)!==l.AST_NODE_TYPES.PropertyDefinition)return;var i=o.decorators,a=i.findIndex(function(r){return r===e});h(r,i.slice(a),n)}}},meta:{docs:{description:"Enforces order of properties decorators"}},name:w});var A;var _={rules:(A={},t(A,g,O),t(A,S,E),t(A,x,D),t(A,P,j),t(A,w,T),A)};module.exports=_;//# sourceMappingURL=index.js.map
"use strict";function r(r,e){if(e==null||e>r.length)e=r.length;for(var t=0,n=new Array(e);t<e;t++)n[t]=r[t];return n}function e(r){if(Array.isArray(r))return r}function t(r,e,t){if(e in r){Object.defineProperty(r,e,{value:t,enumerable:true,configurable:true,writable:true})}else{r[e]=t}return r}function n(r){if(typeof Symbol!=="undefined"&&r[Symbol.iterator]!=null||r["@@iterator"]!=null)return Array.from(r)}function o(r,e){var t=r==null?null:typeof Symbol!=="undefined"&&r[Symbol.iterator]||r["@@iterator"];if(t==null)return;var n=[];var o=true;var a=false;var i,c;try{for(t=t.call(r);!(o=(i=t.next()).done);o=true){n.push(i.value);if(e&&n.length===e)break}}catch(r){a=true;c=r}finally{try{if(!o&&t["return"]!=null)t["return"]()}finally{if(a)throw c}}return n}function a(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function i(r){for(var e=1;e<arguments.length;e++){var n=arguments[e]!=null?arguments[e]:{};var o=Object.keys(n);if(typeof Object.getOwnPropertySymbols==="function"){o=o.concat(Object.getOwnPropertySymbols(n).filter(function(r){return Object.getOwnPropertyDescriptor(n,r).enumerable}))}o.forEach(function(e){t(r,e,n[e])})}return r}function c(r,e){var t=Object.keys(r);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(r);if(e){n=n.filter(function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable})}t.push.apply(t,n)}return t}function u(r,e){e=e!=null?e:{};if(Object.getOwnPropertyDescriptors){Object.defineProperties(r,Object.getOwnPropertyDescriptors(e))}else{c(Object(e)).forEach(function(t){Object.defineProperty(r,t,Object.getOwnPropertyDescriptor(e,t))})}return r}function s(r,t){return e(r)||o(r,t)||d(r,t)||a()}function f(r){return e(r)||n(r)||d(r)||a()}function d(e,t){if(!e)return;if(typeof e==="string")return r(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if(n==="Object"&&e.constructor)n=e.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 r(e,t)}var l=require("@typescript-eslint/types");var v=require("@typescript-eslint/utils");var p={$schema:"http://json-schema.org/draft-07/schema#",additionalProperties:!1,properties:{autoFix:{default:!1,description:"Automatically fix the order.\nWhen set to `true`, only one error is reported and the whole set of decorators is fixed.",type:"boolean"},caseSensitive:{default:!0,description:"If true, enforce properties to be in case-sensitive order.",type:"boolean"},direction:{default:"asc",description:"Specify the direction of the ordering.",enum:["asc","desc"],type:"string"}},type:"object"};var y=v.ESLintUtils.RuleCreator(function(r){return r});function m(r){return y(u(i({},r),{defaultOptions:[{autoFix:!1,caseSensitive:!0,direction:"asc"}],meta:u(i({schema:[p]},r.meta),{docs:u(i({requiresTypeChecking:!1},r.meta.docs),{recommended:"warn"}),fixable:"code",messages:{"incorrect-order":"Expected decorators to be in sorted order. `@{{ after }}` should be before `@{{ previous }}`."},type:"layout"})}))}function b(r){var e=function(r){switch(r.type){case v.AST_NODE_TYPES.CallExpression:return e(r.callee);case v.AST_NODE_TYPES.Identifier:return r.name}throw new Error("Not a valid decorator.")};return e(r.expression)}function h(r,e,t){var n=t.autoFix,o=t.caseSensitive,a=t.direction,i=function(r){var e=b(r);return o?e:e.toLowerCase()},c=function(r,e){var t;return t=s(a==="desc"?[e,r]:[r,e],2),r=t[0],e=t[1],t,r===e?0:r<e?-1:1},u=e.map(function(r){return{name:i(r),node:r}}),d=function(e,t){var n=r.getSourceCode(),o=n.getText(),a=t.slice().sort(function(r,e){var t=r.name,n=e.name;return c(t,n)}).map(function(r){var e=r.node;return e}),i=a.map(function(r,e){var i=e===a.length-1?"":o.slice(t[e].node.range[1],t[e+1].node.range[0]);return n.getText(r)+i});return e.replaceTextRange([t[0].node.range[0],t[t.length-1].node.range[1]],i.join(""))},l=function(e){if(e.length<=1)return;var t=f(e),o=t[0],a=o.name,i=t.slice(1);var u=true,s=false,v=undefined;try{for(var p=i[Symbol.iterator](),y;!(u=(y=p.next()).done);u=true){var m=y.value,b=m.name,h=m.node;if(c(a,b)>0){r.report({data:{after:b,previous:a},fix:n?function(r){return d(r,e)}:void 0,messageId:"incorrect-order",node:h});return}}}catch(r){s=true;v=r}finally{try{if(!u&&p.return!=null){p.return()}}finally{if(s){throw v}}}n&&l(e.slice(1))};l(u)}var g="sort-on-accessors",O=m({create:function(r,e){var t=s(e,1),n=t[0];var o=n.autoFix,a=function(r){var e;var t=r.parent;return((e=t)===null||e===void 0?void 0:e.type)===l.AST_NODE_TYPES.MethodDefinition&&t.kind==="get"?t:!1};return o?{Decorator:function e(e){var t=a(e);if(!t)return;var o=t.decorators;o[0]===e&&h(r,o,n)}}:{Decorator:function e(e){var t=a(e);if(!t)return;var o=t.decorators,i=o.findIndex(function(r){return r===e});h(r,o.slice(i),n)}}},meta:{docs:{description:"Enforces order of accessors decorators"}},name:g});var S="sort-on-classes",E=m({create:function(r,e){var t=s(e,1),n=t[0];var o=n.autoFix;return o?{ClassDeclaration:function e(e){var t=e.decorators;h(r,t!==null&&t!==void 0?t:[],n)}}:{Decorator:function e(e){var t;var o=e.parent;if(((t=o)===null||t===void 0?void 0:t.type)!==l.AST_NODE_TYPES.ClassDeclaration)return;var a=o.decorators,i=a.findIndex(function(r){return r===e});h(r,a.slice(i),n)}}},meta:{docs:{description:"Enforces order of class decorators"}},name:S});var x="sort-on-methods",D=m({create:function(r,e){var t=s(e,1),n=t[0];var o=n.autoFix;return o?{MethodDefinition:function e(e){var t=e.decorators,o=e.kind;o==="method"&&h(r,t,n)}}:{Decorator:function e(e){var t;var o=e.parent;if(((t=o)===null||t===void 0?void 0:t.type)!==l.AST_NODE_TYPES.MethodDefinition)return;var a=o.decorators,i=a.findIndex(function(r){return r===e});h(r,a.slice(i),n)}}},meta:{docs:{description:"Enforces order of methods decorators"}},name:x});var P="sort-on-parameters",w=m({create:function(r,e){var t=s(e,1),n=t[0];var o=n.autoFix,a=function(r){var e,t;var n=r.parent;return((e=n)===null||e===void 0?void 0:e.type)===l.AST_NODE_TYPES.Identifier&&((t=n.parent)===null||t===void 0?void 0:t.type)===l.AST_NODE_TYPES.FunctionExpression?n:!1};return o?{Decorator:function e(e){var t=a(e);if(!t)return;var o=t.decorators;o[0]===e&&h(r,o,n)}}:{Decorator:function e(e){var t=a(e);if(!t)return;var o=t.decorators,i=o.findIndex(function(r){return r===e});h(r,o.slice(i),n)}}},meta:{docs:{description:"Enforces order of parameters decorators"}},name:P});var j="sort-on-properties",T=m({create:function(r,e){var t=s(e,1),n=t[0];var o=n.autoFix;return o?{PropertyDefinition:function e(e){var t=e.decorators;h(r,t!==null&&t!==void 0?t:[],n)}}:{Decorator:function e(e){var t;var o=e.parent;if(((t=o)===null||t===void 0?void 0:t.type)!==l.AST_NODE_TYPES.PropertyDefinition)return;var a=o.decorators,i=a.findIndex(function(r){return r===e});h(r,a.slice(i),n)}}},meta:{docs:{description:"Enforces order of properties decorators"}},name:j});var A="sort-decorators";function _(r){var e;return{parser:"@typescript-eslint/parser",plugins:[A],rules:(e={},t(e,"".concat(A,"/").concat(g),r),t(e,"".concat(A,"/").concat(S),r),t(e,"".concat(A,"/").concat(x),r),t(e,"".concat(A,"/").concat(P),r),t(e,"".concat(A,"/").concat(j),r),e)}}var I=_("warn");var F=_(["error",{autoFix:!0}]);var N;var C={configs:{recommended:I,strict:F},rules:(N={},t(N,g,O),t(N,S,E),t(N,x,D),t(N,P,w),t(N,j,T),N)};module.exports=C;//# sourceMappingURL=index.js.map
# Enforces order of accessors decorators (`sort-decorators/sort-on-accessors`)
💼⚠️ This rule is enabled in the 🔒 `strict` config. This rule _warns_ in the ✅ `recommended` config.
🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).

@@ -4,0 +6,0 @@

# Enforces order of class decorators (`sort-decorators/sort-on-classes`)
💼⚠️ This rule is enabled in the 🔒 `strict` config. This rule _warns_ in the ✅ `recommended` config.
🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).

@@ -4,0 +6,0 @@

# Enforces order of methods decorators (`sort-decorators/sort-on-methods`)
💼⚠️ This rule is enabled in the 🔒 `strict` config. This rule _warns_ in the ✅ `recommended` config.
🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).

@@ -4,0 +6,0 @@

# Enforces order of parameters decorators (`sort-decorators/sort-on-parameters`)
💼⚠️ This rule is enabled in the 🔒 `strict` config. This rule _warns_ in the ✅ `recommended` config.
🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).

@@ -4,0 +6,0 @@

# Enforces order of properties decorators (`sort-decorators/sort-on-properties`)
💼⚠️ This rule is enabled in the 🔒 `strict` config. This rule _warns_ in the ✅ `recommended` config.
🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).

@@ -4,0 +6,0 @@

@@ -87,3 +87,3 @@ {

},
"version": "0.1.0"
"version": "0.2.0"
}

@@ -57,3 +57,20 @@ # eslint-plugin-sort-decorators

> All these configuration can be done on a `override` section:
Or simply extends a configuration preset:
```json
{
"extends": ["plugin:sort-decorators/recommended"]
}
```
### Configuration presets
| Name | Description |
|:-------------------------------------|:---------------------------------------------------------------|
| `plugin:sort-decorators/recommended` | Enables all rules with a `warn` security level. |
| `plugin:sort-decorators/strict` | Enables all rules with a `error` security level and `autoFix`. |
---
> All this configuration can be done on a `override` section:
> <https://eslint.org/docs/latest/use/configure/configuration-files#how-do-overrides-work>

@@ -65,12 +82,20 @@

💼 Configurations enabled in.\
⚠️ Configurations set to warn in.\
✅ Set in the `recommended` configuration.\
🔒 Set in the `strict` configuration.\
🔧 Automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix).
| Name | Description | 🔧 |
| :----------------------------------------------------- | :-------------------------------------- | :- |
| [sort-on-accessors](docs/rules/sort-on-accessors.md) | Enforces order of accessors decorators | 🔧 |
| [sort-on-classes](docs/rules/sort-on-classes.md) | Enforces order of class decorators | 🔧 |
| [sort-on-methods](docs/rules/sort-on-methods.md) | Enforces order of methods decorators | 🔧 |
| [sort-on-parameters](docs/rules/sort-on-parameters.md) | Enforces order of parameters decorators | 🔧 |
| [sort-on-properties](docs/rules/sort-on-properties.md) | Enforces order of properties decorators | 🔧 |
| Name | Description | 💼 | ⚠️ | 🔧 |
| :----------------------------------------------------- | :-------------------------------------- | :- | :- | :- |
| [sort-on-accessors](docs/rules/sort-on-accessors.md) | Enforces order of accessors decorators | 🔒 | ✅ | 🔧 |
| [sort-on-classes](docs/rules/sort-on-classes.md) | Enforces order of class decorators | 🔒 | ✅ | 🔧 |
| [sort-on-methods](docs/rules/sort-on-methods.md) | Enforces order of methods decorators | 🔒 | ✅ | 🔧 |
| [sort-on-parameters](docs/rules/sort-on-parameters.md) | Enforces order of parameters decorators | 🔒 | ✅ | 🔧 |
| [sort-on-properties](docs/rules/sort-on-properties.md) | Enforces order of properties decorators | 🔒 | ✅ | 🔧 |
<!-- end auto-generated rules list -->
## Releases
See information about breaking changes and release notes [here](https://github.com/heap-code/eslint-plugin-sort-decorators/blob/HEAD/CHANGELOG.md).

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc