Skip to content

Commit

Permalink
Add basic handling of parse errors to AST linter
Browse files Browse the repository at this point in the history
refs TryGhost#163
- catch an error from the parse step and push it into the returned messages as a fatal error

Invalid file `test.hbs`:
```hbs
{{#primary_author}}
    {{name}}
{{/author}}
```

Resulting message:
```
[
  {
    "moduleId": "test.hbs",
    "message": "primary_author doesn't match author - 1:3",
    "fatal": true,
    "column": 3,
    "line": 1
  }
]
```
  • Loading branch information
kevinansfield committed Apr 25, 2019
1 parent c0f1fdf commit 6803026
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/ast-linter/linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,18 @@ class Linter {
};

const scanner = this.buildScanner(scannerConfig);
const ast = Handlebars.parse(options.source);
let ast;

try {
ast = Handlebars.parse(options.source);
} catch (err) {
addToMessages({
message: err.message,
fatal: true,
column: err.column,
line: err.lineNumber
});
}

scanner.accept(ast);

Expand Down

0 comments on commit 6803026

Please sign in to comment.