@angular-eslint/eslint-plugin-template
Advanced tools
Comparing version 0.0.1-alpha.31 to 0.0.1-alpha.32
@@ -1,1 +0,1 @@ | ||
var e,t=(e=require("typescript"))&&"object"==typeof e&&"default"in e?e.default:e,n=require("@typescript-eslint/experimental-utils"),r=new Map,a={"extract-inline-html":{preprocess:function(e,n){if(!n.endsWith(".component.ts"))return[e];try{var a=t.createSourceFile(n,e,t.ScriptTarget.Latest,!0),o=a.statements.filter(function(e){return t.isClassDeclaration(e)});if(!o||!o.length)return[e];for(var i=[],s=0,c=o;s<c.length;s+=1){var p=c[s];if(p.decorators)for(var l=0,u=p.decorators;l<u.length;l+=1){var d=u[l];t.isCallExpression(d.expression)&&t.isIdentifier(d.expression.expression)&&"Component"===d.expression.expression.text&&i.push(d)}}if(!i||!i.length)return[e];if(i.length>1)throw new Error("@angular-eslint/eslint-plugin-template currently only supports 1 Component per file");var m=i[0];if(!t.isDecorator(m)||!t.isCallExpression(m.expression)||1!==m.expression.arguments.length)return[e];var g=m.expression.arguments[0];if(!t.isObjectLiteralExpression(g))return[e];var f=g.properties.find(function(e){return e&&e.name&&"template"===e.name.getText()});if(g.properties.find(function(e){return e&&e.name&&"templateUrl"===e.name.getText()})||!f)return[e];if(!t.isPropertyAssignment(f)||!t.isStringLiteralLike(f.initializer))return[e];var x=f.initializer.text,y=function(e,t){var n=e.indexOf(t);return[n,n+t.length]}(e,x);return r.set(n,{range:y,lineAndCharacter:{start:a.getLineAndCharacterOfPosition(y[0]),end:a.getLineAndCharacterOfPosition(y[1])}}),[e,{text:x,filename:"inline-template.component.html"}]}catch(t){if("@angular-eslint/eslint-plugin-template currently only supports 1 Component per file"===t.message)throw t;return console.log(t),console.error("preprocess: ERROR could not parse @Component() metadata",n),[e]}},postprocess:function(e,t){var n=e[0],a=e[1];if(!a||!a.length)return n;var o=r.get(t);return o?n.concat(a.map(function(e){e.line=e.line+o.lineAndCharacter.start.line,e.column=e.column,e.endLine=e.endLine+o.lineAndCharacter.start.line,e.endColumn=e.endColumn;var t=o.range[0];return e.fix.range=[t+e.fix.range[0],t+e.fix.range[1]],e})):n},supportsAutofix:!0}},o=n.ESLintUtils.RuleCreator(function(){return""});function i(e){if(!e.parserServices||!e.parserServices.defineTemplateBodyVisitor||!e.parserServices.convertNodeSourceSpanToLoc)throw new Error("You have used a rule which requires '@angular-eslint/template-parser' to be used as the 'parser' in your ESLint config.");return e.parserServices}var s,c=/\[(.*)\]/,p=o({name:"banana-in-a-box",meta:{type:"suggestion",docs:{description:"Ensures that the two-way data binding syntax is correct",category:"Best Practices",recommended:!1},fixable:"code",schema:[],messages:{bananaInABox:"Invalid binding syntax. Use [(expr)] instead"}},defaultOptions:[],create:function(e){var t=i(e),n=e.getSourceCode();return t.defineTemplateBodyVisitor({BoundEvent:function(r){var a=r.name.match(c);if(a){var o="[("+a[1]+")]",i=t.convertNodeSourceSpanToLoc(r.sourceSpan),s=n.getIndexFromLoc(i.start);e.report({messageId:"bananaInABox",loc:i,fix:function(e){return e.replaceTextRange([s,"(".length+s+")".length+r.name.length],o)}})}}})}}),l=["ngForOf","ngIf","ngSwitchCase"],u=["ngSwitchDefault"],d=o({name:"cyclomatic-complexity",meta:{type:"suggestion",docs:{description:"Checks cyclomatic complexity against a specified limit. It is a quantitative measure of the number of linearly independent paths through a program's source code",category:"Best Practices",recommended:!1},fixable:"code",schema:[{type:"object",properties:{maxComplexity:{type:"number",minimum:1}},additionalProperties:!1}],messages:{cyclomaticComplexity:"The cyclomatic complexity exceeded the defined limit of {{maxComplexity}}. Your template should be refactored."}},defaultOptions:[{maxComplexity:5}],create:function(e,t){var n=t[0],r=0,a=i(e),o=n.maxComplexity,s=function(t){if(!((r+=1)<=o)){var n=a.convertNodeSourceSpanToLoc(t.sourceSpan);e.report({messageId:"cyclomaticComplexity",loc:n,data:{maxComplexity:o}})}};return a.defineTemplateBodyVisitor({BoundAttribute:function(e){l.includes(e.name)&&s(e)},TextAttribute:function(e){u.includes(e.name)&&s(e)}})}}),m=new Set(["$any"]),g=o({name:"no-call-expression",meta:{type:"suggestion",docs:{description:"Disallows calling expressions in templates, except for output handlers.",category:"Best Practices",recommended:!1},schema:[],messages:{noCallExpression:"Avoid calling expressions in templates."}},defaultOptions:[],create:function(e){var t=i(e),n=e.getSourceCode();return t.defineTemplateBodyVisitor({MethodCall:function(t){if(!m.has(t.name)&&"BoundEvent"!==t.parent.parent.type){var r="Interpolation"===t.parent.type?-1:0,a=n.getLocFromIndex(t.sourceSpan.start),o=n.getLocFromIndex(t.sourceSpan.end+r);e.report({messageId:"noCallExpression",loc:{start:a,end:o}})}}})}}),f=o({name:"no-negated-async",meta:{type:"suggestion",docs:{description:"Ensures that strict equality is used when evaluating negations on async pipe output",category:"Best Practices",recommended:!1},fixable:"code",schema:[],messages:{noNegatedAsync:"Async pipes should not be negated. Use (observable | async) === (false | null | undefined) to check its value instead",noLooseEquality:"Async pipes must use strict equality `===` when comparing with `false`"}},defaultOptions:[],create:function(e){var t,n=i(e),r=e.getSourceCode();return n.defineTemplateBodyVisitor(((t={})["BindingPipe[name=async]"]=function(t){if("PrefixNot"!==t.parent.type)if("Binary"!==t.parent.type||"=="!==t.parent.operation);else{var n="Interpolation"===t.parent.parent.type?-2:0,a=r.getLocFromIndex(t.parent.sourceSpan.start+("Interpolation"===t.parent.parent.type?-2:-1)),o=r.getLocFromIndex(t.parent.sourceSpan.end+n);e.report({messageId:"noLooseEquality",loc:{start:a,end:o}})}else{var i="Interpolation"===t.parent.parent.type?-2:0,s=r.getLocFromIndex(t.parent.sourceSpan.start+("Interpolation"===t.parent.parent.type?-1:-0)),c=r.getLocFromIndex(t.parent.sourceSpan.end+i);e.report({messageId:"noNegatedAsync",loc:{start:s,end:c}})}},t))}}),x={processors:a,rules:(s={},s["banana-in-a-box"]=p,s["cyclomatic-complexity"]=d,s["no-call-expression"]=g,s["no-negated-async"]=f,s)};module.exports=x; | ||
var e,t=(e=require("typescript"))&&"object"==typeof e&&"default"in e?e.default:e,n=require("@typescript-eslint/experimental-utils"),r=new Map,a={"extract-inline-html":{preprocess:function(e,n){if(!n.endsWith(".component.ts"))return[e];try{var a=t.createSourceFile(n,e,t.ScriptTarget.Latest,!0),o=a.statements.filter(function(e){return t.isClassDeclaration(e)});if(!o||!o.length)return[e];for(var i=[],s=0,c=o;s<c.length;s+=1){var p=c[s];if(p.decorators)for(var l=0,u=p.decorators;l<u.length;l+=1){var d=u[l];t.isCallExpression(d.expression)&&t.isIdentifier(d.expression.expression)&&"Component"===d.expression.expression.text&&i.push(d)}}if(!i||!i.length)return[e];if(i.length>1)throw new Error("@angular-eslint/eslint-plugin-template currently only supports 1 Component per file");var m=i[0];if(!t.isDecorator(m)||!t.isCallExpression(m.expression)||1!==m.expression.arguments.length)return[e];var g=m.expression.arguments[0];if(!t.isObjectLiteralExpression(g))return[e];var f=g.properties.find(function(e){return e&&e.name&&"template"===e.name.getText()});if(g.properties.find(function(e){return e&&e.name&&"templateUrl"===e.name.getText()})||!f)return[e];if(!t.isPropertyAssignment(f)||!t.isStringLiteralLike(f.initializer))return[e];var x=f.initializer.text,y=function(e,t){var n=e.indexOf(t);return[n,n+t.length]}(e,x);return r.set(n,{range:y,lineAndCharacter:{start:a.getLineAndCharacterOfPosition(y[0]),end:a.getLineAndCharacterOfPosition(y[1])}}),[e,{text:x,filename:"inline-template.component.html"}]}catch(t){if("@angular-eslint/eslint-plugin-template currently only supports 1 Component per file"===t.message)throw t;return console.log(t),console.error("preprocess: ERROR could not parse @Component() metadata",n),[e]}},postprocess:function(e,t){var n=e[0],a=e[1];if(!a||!a.length)return n;var o=r.get(t);return o?n.concat(a.map(function(e){e.line=e.line+o.lineAndCharacter.start.line,e.column=e.column,e.endLine=e.endLine+o.lineAndCharacter.start.line,e.endColumn=e.endColumn;var t=o.range[0];return e.fix.range=[t+e.fix.range[0],t+e.fix.range[1]],e})):n},supportsAutofix:!0}},o=n.ESLintUtils.RuleCreator(function(){return""});function i(e){if(!e.parserServices||!e.parserServices.defineTemplateBodyVisitor||!e.parserServices.convertNodeSourceSpanToLoc)throw new Error("You have used a rule which requires '@angular-eslint/template-parser' to be used as the 'parser' in your ESLint config.");return e.parserServices}var s,c=/\[(.*)\]/,p=o({name:"banana-in-a-box",meta:{type:"suggestion",docs:{description:"Ensures that the two-way data binding syntax is correct",category:"Best Practices",recommended:"error"},fixable:"code",schema:[],messages:{bananaInABox:"Invalid binding syntax. Use [(expr)] instead"}},defaultOptions:[],create:function(e){var t=i(e),n=e.getSourceCode();return t.defineTemplateBodyVisitor({BoundEvent:function(r){var a=r.name.match(c);if(a){var o="[("+a[1]+")]",i=t.convertNodeSourceSpanToLoc(r.sourceSpan),s=n.getIndexFromLoc(i.start);e.report({messageId:"bananaInABox",loc:i,fix:function(e){return e.replaceTextRange([s,"(".length+s+")".length+r.name.length],o)}})}}})}}),l=["ngForOf","ngIf","ngSwitchCase"],u=["ngSwitchDefault"],d=o({name:"cyclomatic-complexity",meta:{type:"suggestion",docs:{description:"Checks cyclomatic complexity against a specified limit. It is a quantitative measure of the number of linearly independent paths through a program's source code",category:"Best Practices",recommended:!1},fixable:"code",schema:[{type:"object",properties:{maxComplexity:{type:"number",minimum:1}},additionalProperties:!1}],messages:{cyclomaticComplexity:"The cyclomatic complexity exceeded the defined limit of {{maxComplexity}}. Your template should be refactored."}},defaultOptions:[{maxComplexity:5}],create:function(e,t){var n=t[0],r=0,a=i(e),o=n.maxComplexity,s=function(t){if(!((r+=1)<=o)){var n=a.convertNodeSourceSpanToLoc(t.sourceSpan);e.report({messageId:"cyclomaticComplexity",loc:n,data:{maxComplexity:o}})}};return a.defineTemplateBodyVisitor({BoundAttribute:function(e){l.includes(e.name)&&s(e)},TextAttribute:function(e){u.includes(e.name)&&s(e)}})}}),m=new Set(["$any"]),g=o({name:"no-call-expression",meta:{type:"suggestion",docs:{description:"Disallows calling expressions in templates, except for output handlers.",category:"Best Practices",recommended:!1},schema:[],messages:{noCallExpression:"Avoid calling expressions in templates."}},defaultOptions:[],create:function(e){var t=i(e),n=e.getSourceCode();return t.defineTemplateBodyVisitor({MethodCall:function(t){if(!m.has(t.name)&&"BoundEvent"!==t.parent.parent.type){var r="Interpolation"===t.parent.type?-1:0,a=n.getLocFromIndex(t.sourceSpan.start),o=n.getLocFromIndex(t.sourceSpan.end+r);e.report({messageId:"noCallExpression",loc:{start:a,end:o}})}}})}}),f=o({name:"no-negated-async",meta:{type:"suggestion",docs:{description:"Ensures that strict equality is used when evaluating negations on async pipe output",category:"Best Practices",recommended:"error"},fixable:"code",schema:[],messages:{noNegatedAsync:"Async pipes should not be negated. Use (observable | async) === (false | null | undefined) to check its value instead",noLooseEquality:"Async pipes must use strict equality `===` when comparing with `false`"}},defaultOptions:[],create:function(e){var t,n=i(e),r=e.getSourceCode();return n.defineTemplateBodyVisitor(((t={})["BindingPipe[name=async]"]=function(t){if("PrefixNot"!==t.parent.type)if("Binary"!==t.parent.type||"=="!==t.parent.operation);else{var n="Interpolation"===t.parent.parent.type?-2:0,a=r.getLocFromIndex(t.parent.sourceSpan.start+("Interpolation"===t.parent.parent.type?-2:-1)),o=r.getLocFromIndex(t.parent.sourceSpan.end+n);e.report({messageId:"noLooseEquality",loc:{start:a,end:o}})}else{var i="Interpolation"===t.parent.parent.type?-2:0,s=r.getLocFromIndex(t.parent.sourceSpan.start+("Interpolation"===t.parent.parent.type?-1:-0)),c=r.getLocFromIndex(t.parent.sourceSpan.end+i);e.report({messageId:"noNegatedAsync",loc:{start:s,end:c}})}},t))}}),x={processors:a,rules:(s={},s["banana-in-a-box"]=p,s["cyclomatic-complexity"]=d,s["no-call-expression"]=g,s["no-negated-async"]=f,s)};module.exports=x; |
{ | ||
"name": "@angular-eslint/eslint-plugin-template", | ||
"version": "0.0.1-alpha.31", | ||
"version": "0.0.1-alpha.32", | ||
"description": "ESLint plugin for Angular Templates", | ||
@@ -28,3 +28,3 @@ "license": "MIT", | ||
"devDependencies": { | ||
"@angular-eslint/utils": "^0.0.1-alpha.31" | ||
"@angular-eslint/utils": "^0.0.1-alpha.32" | ||
}, | ||
@@ -36,3 +36,3 @@ "peerDependencies": { | ||
}, | ||
"gitHead": "c040f7961599e6da193cd2f0241f995eba2cf957" | ||
"gitHead": "44392627ecd2e2cd332f1a9f47c0fec8dfaa5e59" | ||
} |
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
13269