Skip to content

Commit

Permalink
* Finalise 0.8
Browse files Browse the repository at this point in the history
update README.
fix type checking of method return type
support javascript sources. closes #52
Migrate conflicting-attribute. closes #32
ensure unknown converters fail silently.
Check bindable field is okay. ref #35
Support Syntax Rule configuration
Support any attribute order for controllers. ref #35
Support Keyed Access.  ref #35
Fix negated if.bind
support interpolation within binding.
support custom typings. closes #36
reject access to private fields. ref: #35
support ancestor scope with correct context ref: #35
fix view-model resolution. ref: #35
fix inheriting locals ref: #35
update and unlock versions
improve unhandled error msg
replace repeatfor. closes #40
fix view-model not found
rework static-type rule closes #33
  • Loading branch information
MeirionHughes committed Jul 1, 2016
1 parent e363183 commit 8f706df
Show file tree
Hide file tree
Showing 26 changed files with 1,695 additions and 1,090 deletions.
99 changes: 55 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,37 +33,44 @@ using the default config (plus type checking - *see below*), the example:

***foo.html***
```html
1:<template>
2: <require></require>
3: <div repeat="item of items"></div>
4: <div repeat.for="item of"></div>
5: <content></content>
6: <slot></slot>
7: <slot></slot>
8: <table>
9: <template></template>
10: </table>
11: <div style="width: ${width}px; height: ${height}px;"></div>
12: <div repeat.for="item of items" with.bind="items">
13: </div>
14: <template repeat.for="item of items">
15: ${item.ino}
16: ${item.role.isAdmn}
17: ${item.update().sizeee}
01:<template>
02: <require/>
03: <div repeat.for="item of"></div>
04: <content></content>
05: <slot></slot><slot></slot>
06: <table>
07: <template></template>
08: </table>
09: <div style="width: ${width}px; height: ${height}px;"></div>
10: <div repeat.for="item of items" with.bind="items"></div>
11: <template repeat.for="item of items">
12: ${item.ino}
13: ${item.role.isAdmn}
14: ${item.update().sizeee}
15: </template>
16: <template with.bind="person">
17: ${address.postcdo}
18: </template>
19: <template with.bind="person">
20: ${address.postcdo}
21: </template>
22:</etemps>
19: <table>
20: <tr repeat.for="item of items">
21: <td>${item.nme}</td>
22: </tr>
23: </table>
24: <div value.bind="car.modl"></div>
25:</etemps>
```
***foo.ts***
```ts
import {Person} from './my-types/person';
import {Item} from './my-types/item';
import {Car} from 'my-lib';

export class FooViewModel {
person: Person;
items: Item[];
car: Car;
width:number;
height:number;
}
```

Expand All @@ -73,23 +80,25 @@ will result in the following errors:
suspected unclosed element detected [ln: 1 col: 1]
self-closing element [ln: 2 col: 3]
require tag is missing a 'from' attribute [ln: 2 col: 3]
did you miss `.for` on repeat? [ln: 3 col: 3]
repeat syntax should be of form `* of *` [ln: 4 col: 3]
<content> is obsolete [ln: 5 col: 3]
Incorrect syntax for "for" [ln: 3 col: 8]
* The form is: "$local of $items" or "[$key, $value] of $items",
<content> is obsolete [ln: 4 col: 3]
* use slot instead
more than one default slot detected [ln: 7 col: 3]
template as child of <table> not allowed [ln: 9 col: 5]
interpolation not allowed in style attribute [ln: 11 col: 3]
conflicting attributes: [repeat.for, with.bind] [ln: 12 col: 3]
more than one default slot detected [ln: 5 col: 16]
template as child of <table> not allowed [ln: 7 col: 5]
interpolation not allowed in style attribute [ln: 9 col: 3]
conflicting attributes: [repeat.for, with.bind] [ln: 10 col: 3]
* template controllers shouldn't be placed on the same element
cannot find 'ino' in type 'Item' [ln: 15 col: 0]
cannot find 'isAdmn' in type 'Role' [ln: 16 col: 0]
cannot find 'sizeee' in type 'Data' [ln: 17 col: 0]
cannot find 'postcdo' in type 'Address' [ln: 20 col: 0]
mismatched close tag [ln: 22 col: 1]
cannot find 'ino' in type 'Item' [ln: 13 col: 5]
cannot find 'isAdmn' in type 'Role' [ln: 15 col: 5]
cannot find 'sizeee' in type 'Data' [ln: 17 col: 5]
cannot find 'postcdo' in type 'Address' [ln: 18 col: 5]
cannot find 'nme' in type 'Item' [ln: 21 col: 11]
cannot find 'modl' in type 'Car' [ln: 24 col: 8]
mismatched close tag [ln: 25 col: 3]
```

the full example is available in the repository.
The full example is available in the repository; including the custom typings.

## Rules
Rules used by default:
Expand All @@ -111,16 +120,14 @@ Rules used by default:
* *don't allow more than one default slot;*
* **Require**
* *ensure require elments have a 'from' attribute*
* **RepeatFor**
* *ensure loop is well formed*
* **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)*
* **Template**
* *ensure root is a template element, unless its <html>*
* *no more than one template element present*
* **StaticType**
* **optional** *given a list of TypeScript source-files...*
* *given a list of TypeScript source-files...*
* *ensure fields exist in known types*

I'm more than happy to add or improve rules;
Expand All @@ -144,8 +151,7 @@ var linter = new AureliaLinter();
var html = "<template></template>"

linter.lint(html)
.then((errors) => {
errors = errors.sort((a,b)=> a.line - b.line);
.then((errors) => {
errors.forEach(error => {
console.log(`${error.message} [ln: ${error.line} col: ${error.column}]`);
if(error.detail) console.log(` * ${error.detail}`);
Expand Down Expand Up @@ -174,7 +180,7 @@ class Config {
{
attr:/^style$/,
not:/\${(.?)+}/,
msg:"interpolation not allowed for attribute"
msg:"interpolation not allowed in style attribute"
},
{
attr:/^bindable$/,
Expand Down Expand Up @@ -224,17 +230,22 @@ class Config {
containers: Array<string> = ['table', 'select'];
customRules: Rule[] = [];

useStaticTyping = false;
sourceFileGlob = "source/**/*.ts"
useStaticTyping = false;
throwStaticTypingErrors = false;
errorOnNonPublicAccess = true;

sourceFileGlob = "source/**/*.ts";
typingsFileGlob = "typings/**/*.d.ts";
}
```

## Static Types
In order to use static type checking you must opt-in and call initialise with a globbing pattern to include *TypeScript* files.
You must pass the file name (relative) of the html file to the linter.

your templates (for now) must be side-by-side, i.e: *"source/foo.html"* and *"source/foo.ts"*
plus they should export a class of the form *Foo* or *FooViewModel* or *FooVM*
your templates (for now) must be side-by-side, i.e: *"source/foo.html"* and *"source/foo.ts"*.
It is also posible to change the glob configuration to include `js` files instead; but this can only
check first-depth access.

```js
var config = new Config();
Expand Down
1 change: 1 addition & 0 deletions example.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var config = new Config();

config.useStaticTyping = true;
config.sourceFileGlob = "example/**/*.ts";
config.typingsFileGlob = "typings/my-lib.d.ts"

var linter = new AureliaLinter(config);

Expand Down
1 change: 1 addition & 0 deletions example/foo.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@
<td>${item.nme}</td>
</tr>
</table>
${car.modl}
</etemps>
4 changes: 4 additions & 0 deletions example/foo.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import {Person} from './my-types/person';
import {Item} from './my-types/item';
import {Car} from 'my-lib';

export class FooViewModel {
person: Person;
items: Item[];
car: Car;
width:number;
height:number;
}
4 changes: 4 additions & 0 deletions example/my-types/generic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export class Generic<T>
{
value:T;
}
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@
"dependencies": {
"aurelia-binding": "^1.0.0-rc.1.0.2",
"aurelia-dependency-injection": "^1.0.0-rc.1.0.0",
"aurelia-pal-nodejs": "latest",
"aurelia-polyfills": "latest",
"aurelia-templating": "latest",
"aurelia-templating-binding": "latest",
"aurelia-pal-nodejs": "0.1.5",
"aurelia-polyfills": "^1.0.0-rc.1.0.0",
"aurelia-templating": "^1.0.0-rc.1.0.0",
"aurelia-templating-binding": "^1.0.0-rc.1.0.0",
"glob": "7.0.x",
"parse5": "2.1.x",
"template-lint": "0.7.x",
Expand Down
Loading

0 comments on commit 8f706df

Please sign in to comment.