Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- Enhanched the require rule with an extra required attribute from.bind, this or the from are now required #194

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)*
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 5 additions & 14 deletions source/ast.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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;
}
Expand Down
18 changes: 8 additions & 10 deletions source/aurelia-linter.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions source/aurelia-reflection.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
27 changes: 16 additions & 11 deletions source/rules/binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
9 changes: 4 additions & 5 deletions source/rules/require.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 => (<any>x).name == 'from');
let result = attrs.find(x => x.name === 'from' || x.name === 'from.bind');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't support fromt.bind in <require/>, may I know why this was added?


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
});
Expand Down
5 changes: 3 additions & 2 deletions source/rules/slot.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion source/rules/template.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 3 additions & 4 deletions spec/ast.spec.ts
Original file line number Diff line number Diff line change
@@ -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", () => {

Expand Down
8 changes: 4 additions & 4 deletions spec/binding.spec.ts
Original file line number Diff line number Diff line change
@@ -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", () => {

Expand Down
8 changes: 5 additions & 3 deletions spec/failing.spec.ts
Original file line number Diff line number Diff line change
@@ -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();

Expand Down
8 changes: 3 additions & 5 deletions spec/id-attribute.spec.ts
Original file line number Diff line number Diff line change
@@ -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", () => {
Expand Down
2 changes: 1 addition & 1 deletion spec/repeatfor.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Linter } from 'template-lint';

import { Linter, Rule } from 'template-lint';
import { ASTBuilder } from '../source/ast';

describe("RepeatFor Testing", () => {
Expand Down
10 changes: 9 additions & 1 deletion spec/require.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Linter } from 'template-lint';

import { Linter, Rule } from 'template-lint';
import { RequireRule } from '../source/rules/require';

describe("Require Rule", () => {
Expand All @@ -16,6 +16,14 @@ describe("Require Rule", () => {
});
});

it("will pass require elements with a from.bind attribute", (done) => {
linter.lint('<template><require from.bind="something"></require></template>')
.then((issues) => {
expect(issues.length).toBe(0);
done();
});
});

it("will reject require elements without a from attribute", (done) => {
linter.lint('<template><require fgh="something"></require></template>')
.then((issues) => {
Expand Down
2 changes: 1 addition & 1 deletion spec/required-attr.spec.ts
Original file line number Diff line number Diff line change
@@ -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", () => {
Expand Down
2 changes: 1 addition & 1 deletion spec/slot.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Linter } from 'template-lint';

import { Linter, Rule } from 'template-lint';
import { SlotRule } from '../source/rules/slot';

describe("Slot Rule", () => {
Expand Down
2 changes: 1 addition & 1 deletion spec/template.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Linter } from 'template-lint';

import { Linter, Rule } from 'template-lint';
import { TemplateRule } from '../source/rules/template';

describe("Template Rule", () => {
Expand Down
7 changes: 3 additions & 4 deletions spec/triage.spec.ts
Original file line number Diff line number Diff line change
@@ -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", () => {
Expand Down