Skip to content

Commit 3cd6022

Browse files
add custom plugin sample
1 parent ddbafff commit 3cd6022

File tree

7 files changed

+3257
-0
lines changed

7 files changed

+3257
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"brightscript.bsdk": "node_modules\\brighterscript"
3+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { CompilerPlugin, BscFile, isBrsFile } from 'brighterscript';
2+
3+
// plugin factory
4+
export default function () {
5+
return {
6+
name: 'no-underscores',
7+
// post-parsing validation
8+
afterFileValidate: (file: BscFile) => {
9+
if (isBrsFile(file)) {
10+
// visit function statements and validate their name
11+
file.parser.references.functionStatements.forEach((fun) => {
12+
if (fun.name.text.includes('_')) {
13+
file.addDiagnostics([{
14+
code: 'custom:9000',
15+
message: 'Do not use underscores in function names',
16+
range: fun.name.range,
17+
file
18+
}]);
19+
}
20+
});
21+
}
22+
}
23+
} as CompilerPlugin;
24+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"rootDir": "src",
3+
"plugins": [
4+
"./bsc-custom-plugin.ts"
5+
],
6+
"require": [
7+
"ts-node/register"
8+
]
9+
}

0 commit comments

Comments
 (0)