diff --git a/README.md b/README.md index cf5f5c4..7e65698 100644 --- a/README.md +++ b/README.md @@ -346,7 +346,7 @@ Rules used by default: * *don't allow two, or more, slots to have the same name;* * *don't allow more than one default slot;* * **Require** - * *ensure require elments have a 'from' attribute* + * *ensure require elments have the 'from' or 'from.bind' attribute* * **ConflictingAttributes** * *ensure element doesn't have attribute combination marked as conflicting.* * *i.e. template controller attributes (`if.bind` and `repeat.for` on the same element)* diff --git a/package-lock.json b/package-lock.json index 862e01b..8042810 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "aurelia-template-lint", - "version": "0.9.25", + "version": "0.10.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/source/ast.ts b/source/ast.ts index 7f6e976..435f890 100644 --- a/source/ast.ts +++ b/source/ast.ts @@ -1,18 +1,9 @@ -import { TemplatingBindingLanguage, InterpolationBindingExpression } from 'aurelia-templating-binding'; -import { AccessMember, AccessScope, AccessKeyed, NameExpression, ValueConverter } from 'aurelia-binding'; -import { Container } from 'aurelia-dependency-injection'; -import { Rule, Parser, ParserState, Issue, IssueSeverity } from 'template-lint'; -import ts = require('typescript'); +import { InterpolationBindingExpression } from 'aurelia-templating-binding'; +import { Rule, Parser, Issue, IssueSeverity } from 'template-lint'; + +import ts = require('typescript'); -import { - ViewResources, - BindingLanguage, - BehaviorInstruction, - HtmlBehaviorResource, - ViewFactory -} - from 'aurelia-templating'; import { ASTAttribute as P5ASTAttribute } from "parse5"; import { AureliaReflection } from './aurelia-reflection'; @@ -51,7 +42,7 @@ export class ASTBuilder extends Rule { current = next; }); - parser.on("endTag", (tag, attrs, selfClosing, loc) => { + parser.on("endTag", () => { if (current.parent === null) { return; } diff --git a/source/aurelia-linter.ts b/source/aurelia-linter.ts index 0eb6d40..dd9023b 100644 --- a/source/aurelia-linter.ts +++ b/source/aurelia-linter.ts @@ -1,5 +1,4 @@ -import { Linter, Rule, Issue, IssueSeverity } from 'template-lint'; - +import { Linter, Issue } from 'template-lint'; import { ParserBuilder } from 'template-lint'; import { SelfCloseRule } from 'template-lint'; import { StructureRule } from 'template-lint'; @@ -10,18 +9,17 @@ import { AttributeValueRule } from 'template-lint'; import { ValidChildRule } from 'template-lint'; import { ConflictingAttributesRule, ConflictingAttributes } from 'template-lint'; +import { initialize } from 'aurelia-pal-nodejs'; -import { RequireRule } from './rules/require'; -import { SlotRule } from './rules/slot'; -import { TemplateRule } from './rules/template'; -import { BindingRule } from './rules/binding'; -import { RequiredAttributeRule } from './rules/required-attr'; - -import { Reflection } from './reflection'; import { AureliaReflection } from './aurelia-reflection'; import { Config } from './config'; +import { Reflection } from './reflection'; -import { initialize } from 'aurelia-pal-nodejs'; +import { BindingRule } from './rules/binding'; +import { RequireRule } from './rules/require'; +import { RequiredAttributeRule } from './rules/required-attr'; +import { SlotRule } from './rules/slot'; +import { TemplateRule } from './rules/template'; initialize(); diff --git a/source/aurelia-reflection.ts b/source/aurelia-reflection.ts index 675d3a7..7baa450 100644 --- a/source/aurelia-reflection.ts +++ b/source/aurelia-reflection.ts @@ -1,7 +1,7 @@ +import { TemplatingBindingLanguage, InterpolationBindingExpression } from "aurelia-templating-binding"; +import { ViewResources } from "aurelia-templating"; -import { TemplatingBindingLanguage, InterpolationBindingExpression } from "aurelia-templating-binding"; -import { ViewResources, BindingLanguage, BehaviorInstruction } from "aurelia-templating"; import { Container } from "aurelia-dependency-injection"; export class AureliaReflection { diff --git a/source/rules/binding.ts b/source/rules/binding.ts index a172b93..c7117f2 100644 --- a/source/rules/binding.ts +++ b/source/rules/binding.ts @@ -2,16 +2,23 @@ import "aurelia-polyfills"; -import { TemplatingBindingLanguage, InterpolationBindingExpression } from "aurelia-templating-binding"; -import { ViewResources, BindingLanguage, BehaviorInstruction } from "aurelia-templating"; -import { AccessMember, AccessScope, AccessKeyed, Expression, NameExpression, ValueConverter, ListenerExpression } from "aurelia-binding"; -import { Container } from "aurelia-dependency-injection"; +import { BehaviorInstruction } from "aurelia-templating"; + +import { NameExpression, ListenerExpression } from "aurelia-binding"; + import * as ts from "typescript"; + import * as Path from "path"; -import { Rule, Parser, ParserState, Issue, IssueSeverity } from "template-lint"; -import { Reflection } from "../reflection"; -import { AureliaReflection } from '../aurelia-reflection'; +import { Parser, Issue, IssueSeverity } from "template-lint"; + +import Node = ts.Node; + +import NodeArray = ts.NodeArray; + +import Decorator = ts.Decorator; + +import Identifier = ts.Identifier; import { ASTBuilder, @@ -22,10 +29,8 @@ import { ASTContext, FileLoc } from "../ast"; -import Node = ts.Node; -import NodeArray = ts.NodeArray; -import Decorator = ts.Decorator; -import Identifier = ts.Identifier; +import { AureliaReflection } from '../aurelia-reflection'; +import { Reflection } from "../reflection"; /** * Rule to ensure static type usage is valid diff --git a/source/rules/require.ts b/source/rules/require.ts index 643d5aa..de6db79 100644 --- a/source/rules/require.ts +++ b/source/rules/require.ts @@ -1,8 +1,7 @@ "use strict"; -import { Rule, Parser, Issue, IssueSeverity } from 'template-lint'; - +import { Rule, Parser, Issue } from 'template-lint'; /** * Rule to ensure require element is well formed @@ -11,16 +10,16 @@ export class RequireRule extends Rule { init(parser: Parser) { var self = this; - parser.on('startTag', (name, attrs, selfClosing, location) => { + parser.on('startTag', (name, attrs, _, location) => { if (name != 'require') return; - let result = attrs.find(x => (x).name == 'from'); + let result = attrs.find(x => x.name === 'from' || x.name === 'from.bind'); if (!result) { let error = new Issue({ - message: "require tag is missing a 'from' attribute", + message: "require tag is missing a 'from' of 'from.bind' attribute", line: location.line, column: location.col }); diff --git a/source/rules/slot.ts b/source/rules/slot.ts index 2cf2277..ac3a611 100644 --- a/source/rules/slot.ts +++ b/source/rules/slot.ts @@ -1,8 +1,9 @@ "use strict"; -import { Rule, Parser, Issue, IssueSeverity } from 'template-lint'; -import { Attribute, StartTagLocationInfo } from 'parse5'; +import { Rule, Parser, Issue } from 'template-lint'; + +import { StartTagLocationInfo } from 'parse5'; /** * Rule to ensure root element is the template element diff --git a/source/rules/template.ts b/source/rules/template.ts index ae07730..02c2596 100644 --- a/source/rules/template.ts +++ b/source/rules/template.ts @@ -1,7 +1,7 @@ "use strict"; -import { Rule, Parser, Issue, IssueSeverity } from 'template-lint'; +import { Rule, Parser, Issue } from 'template-lint'; /** * Rule to ensure root element is the template element diff --git a/spec/ast.spec.ts b/spec/ast.spec.ts index 569d243..d60a0e1 100644 --- a/spec/ast.spec.ts +++ b/spec/ast.spec.ts @@ -1,10 +1,9 @@ +import { Linter } from 'template-lint'; -import { Linter, Rule } from 'template-lint'; -import { BindingRule } from '../source/rules/binding'; -import { Reflection } from '../source/reflection'; -import { ASTNode, ASTContext, ASTBuilder, ASTElementNode } from '../source/ast'; import * as ts from 'typescript'; +import { ASTNode, ASTContext, ASTBuilder, ASTElementNode } from '../source/ast'; + describe("Abstract Syntax Tree", () => { it("inheritLocals returns all unique locals from self and parents", () => { diff --git a/spec/binding.spec.ts b/spec/binding.spec.ts index 919ee7f..184d464 100644 --- a/spec/binding.spec.ts +++ b/spec/binding.spec.ts @@ -1,9 +1,9 @@ -import { Linter, Rule } from 'template-lint'; -import { BindingRule } from '../source/rules/binding'; -import { Reflection } from '../source/reflection'; +import { Linter } from 'template-lint'; + import { AureliaReflection } from '../source/aurelia-reflection'; -import { ASTNode } from '../source/ast'; +import { Reflection } from '../source/reflection'; +import { BindingRule } from '../source/rules/binding'; describe("Static-Type Binding Tests", () => { diff --git a/spec/failing.spec.ts b/spec/failing.spec.ts index 8fb74dd..19e34b5 100644 --- a/spec/failing.spec.ts +++ b/spec/failing.spec.ts @@ -1,11 +1,13 @@ "use strict"; import { Linter, Rule } from 'template-lint'; -import { Config } from '../source/config'; + +import { initialize } from 'aurelia-pal-nodejs'; + import { AureliaLinter } from '../source/aurelia-linter'; -import { BindingRule } from '../source/rules/binding'; +import { Config } from '../source/config'; import { Reflection } from '../source/reflection'; -import { initialize } from 'aurelia-pal-nodejs'; +import { BindingRule } from '../source/rules/binding'; initialize(); diff --git a/spec/id-attribute.spec.ts b/spec/id-attribute.spec.ts index d8cb55d..4fb6827 100644 --- a/spec/id-attribute.spec.ts +++ b/spec/id-attribute.spec.ts @@ -1,12 +1,10 @@ "use strict"; -import { Linter, Rule } from 'template-lint'; -import { Config } from '../source/config'; -import { AureliaLinter } from '../source/aurelia-linter'; -import { BindingRule } from '../source/rules/binding'; -import { Reflection } from '../source/reflection'; import { initialize } from 'aurelia-pal-nodejs'; +import { AureliaLinter } from '../source/aurelia-linter'; +import { Config } from '../source/config'; + initialize(); describe("ID Attribute Rule", () => { diff --git a/spec/repeatfor.spec.ts b/spec/repeatfor.spec.ts index c164c88..d10b112 100644 --- a/spec/repeatfor.spec.ts +++ b/spec/repeatfor.spec.ts @@ -1,5 +1,5 @@ +import { Linter } from 'template-lint'; -import { Linter, Rule } from 'template-lint'; import { ASTBuilder } from '../source/ast'; describe("RepeatFor Testing", () => { diff --git a/spec/require.spec.ts b/spec/require.spec.ts index c38b0d9..6504d93 100644 --- a/spec/require.spec.ts +++ b/spec/require.spec.ts @@ -1,5 +1,5 @@ +import { Linter } from 'template-lint'; -import { Linter, Rule } from 'template-lint'; import { RequireRule } from '../source/rules/require'; describe("Require Rule", () => { @@ -16,6 +16,14 @@ describe("Require Rule", () => { }); }); + it("will pass require elements with a from.bind attribute", (done) => { + linter.lint('') + .then((issues) => { + expect(issues.length).toBe(0); + done(); + }); + }); + it("will reject require elements without a from attribute", (done) => { linter.lint('') .then((issues) => { diff --git a/spec/required-attr.spec.ts b/spec/required-attr.spec.ts index 751eca7..00c4411 100644 --- a/spec/required-attr.spec.ts +++ b/spec/required-attr.spec.ts @@ -1,5 +1,5 @@ +import { Linter } from 'template-lint'; -import { Linter, Rule } from 'template-lint'; import { RequiredAttributeRule } from '../source/rules/required-attr'; describe("Required Attribute Rule", () => { diff --git a/spec/slot.spec.ts b/spec/slot.spec.ts index eb2d5ae..426bad2 100644 --- a/spec/slot.spec.ts +++ b/spec/slot.spec.ts @@ -1,5 +1,5 @@ +import { Linter } from 'template-lint'; -import { Linter, Rule } from 'template-lint'; import { SlotRule } from '../source/rules/slot'; describe("Slot Rule", () => { diff --git a/spec/template.spec.ts b/spec/template.spec.ts index 585d55c..28e8083 100644 --- a/spec/template.spec.ts +++ b/spec/template.spec.ts @@ -1,5 +1,5 @@ +import { Linter } from 'template-lint'; -import { Linter, Rule } from 'template-lint'; import { TemplateRule } from '../source/rules/template'; describe("Template Rule", () => { diff --git a/spec/triage.spec.ts b/spec/triage.spec.ts index ce83948..a4e000e 100644 --- a/spec/triage.spec.ts +++ b/spec/triage.spec.ts @@ -1,9 +1,8 @@ +import { Linter } from 'template-lint'; -import { Linter, Rule } from 'template-lint'; -import { BindingRule } from '../source/rules/binding'; -import { Reflection } from '../source/reflection'; import { AureliaReflection } from '../source/aurelia-reflection'; -import { ASTNode } from '../source/ast'; +import { Reflection } from '../source/reflection'; +import { BindingRule } from '../source/rules/binding'; /* Triage - Make sure stuff doesn't blow-up for the time-being. */ describe("Triage", () => {