Created
June 1, 2016 09:45
-
-
Save andrei-markeev/496a0e595075b478619ecc68d6844e79 to your computer and use it in GitHub Desktop.
Simple lint based on TS compiler API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as ts from 'typescript'; // don't forget to "npm install typescript -g && npm link typescript" | |
var codeToAnalyse = ` | |
function f1() {} | |
var x = 10; | |
function hello() { function hmm() {} } | |
`; | |
var source = ts.createSourceFile("test.ts", codeToAnalyse, ts.ScriptTarget.ES5); | |
analyse(source); | |
function analyse(node: ts.Node) | |
{ | |
if (node.kind == ts.SyntaxKind.FunctionDeclaration) | |
{ | |
var name = (<ts.FunctionDeclaration>node).name.text; | |
if (name.length < 5) | |
{ | |
console.warn("Function name " + name + " is too short. Provide a better name please!"); | |
} | |
} | |
ts.forEachChild(node, analyse); | |
} | |
// output: | |
// Function name f1 is too short. Provide a better name please! | |
// Function name hmm is too short. Provide a better name please! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment