22// Licensed under the MIT License.
33'use strict' ;
44Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
5+ const path = require ( "path" ) ;
56const Lint = require ( "tslint" ) ;
67const ts = require ( "typescript" ) ;
8+ const util = require ( "../util" ) ;
79const baseRuleWalker_1 = require ( "./baseRuleWalker" ) ;
810const methodNames = [
9- // From IApplicationShell (vscode.window)
11+ // From IApplicationShell (vscode.window):
1012 'showErrorMessage' , 'showInformationMessage' ,
1113 'showWarningMessage' , 'setStatusBarMessage' ,
12- // From IOutputChannel (vscode.OutputChannel)
14+ // From IOutputChannel (vscode.OutputChannel):
1315 'appendLine' , 'appendLine'
1416] ;
17+ // tslint:ignore-next-line:no-suspicious-comments
18+ // TODO: Ideally we would not ignore any files.
19+ const ignoredFiles = util . getListOfFiles ( 'unlocalizedFiles.json' ) ;
20+ const ignoredPrefix = path . normalize ( 'src/test' ) ;
1521const failureMessage = 'Messages must be localized in the Python Extension (use src/client/common/utils/localize.ts)' ;
1622class NoStringLiteralsInMessages extends baseRuleWalker_1 . BaseRuleWalker {
1723 visitCallExpression ( node ) {
18- const prop = node . expression ;
19- if ( ! this . sholdIgnoreCcurrentFile ( node ) &&
20- ts . isPropertyAccessExpression ( node . expression ) &&
21- methodNames . indexOf ( prop . name . text ) >= 0 ) {
24+ if ( ! this . shouldIgnoreNode ( node ) ) {
2225 node . arguments
2326 . filter ( arg => ts . isStringLiteral ( arg ) || ts . isTemplateLiteral ( arg ) )
2427 . forEach ( arg => {
@@ -27,6 +30,34 @@ class NoStringLiteralsInMessages extends baseRuleWalker_1.BaseRuleWalker {
2730 }
2831 super . visitCallExpression ( node ) ;
2932 }
33+ shouldIgnoreCurrentFile ( node ) {
34+ //console.log('');
35+ //console.log(node.getSourceFile().fileName);
36+ //console.log(ignoredFiles);
37+ if ( super . shouldIgnoreCurrentFile ( node , ignoredFiles ) ) {
38+ return true ;
39+ }
40+ const sourceFile = node . getSourceFile ( ) ;
41+ if ( sourceFile && sourceFile . fileName ) {
42+ if ( sourceFile . fileName . startsWith ( ignoredPrefix ) ) {
43+ return true ;
44+ }
45+ }
46+ return false ;
47+ }
48+ shouldIgnoreNode ( node ) {
49+ if ( this . shouldIgnoreCurrentFile ( node ) ) {
50+ return true ;
51+ }
52+ if ( ! ts . isPropertyAccessExpression ( node . expression ) ) {
53+ return true ;
54+ }
55+ const prop = node . expression ;
56+ if ( methodNames . indexOf ( prop . name . text ) < 0 ) {
57+ return true ;
58+ }
59+ return false ;
60+ }
3061}
3162class Rule extends Lint . Rules . AbstractRule {
3263 apply ( sourceFile ) {
0 commit comments