2016-01-14 4 views
2

Я слежу за учебниками от Dan Wahlin и онлайн-примерами для настройки Gulp и Typcript. У меня работает код, но я не могу заставить tslint() работать. Вызов tslint() всегда выдает исключение:TypeError: Невозможно прочитать свойство getFullWidth неопределенного с TSLint и TypeScript

node_modules\tslint\lib\language\walker\ruleWalker.js:18 
    this.limit = this.sourceFile.getFullWidth(); 
           ^

TypeError: Cannot read property 'getFullWidth' of undefined 
at EnableDisableRulesWalker.RuleWalker [as constructor] (C:\Users\sscott\Development\OntarioDarts.com\node_modules\tslint\lib\language\walker\ruleWalker.js:18:37) 
at EnableDisableRulesWalker.SkippableTokenAwareRuleWalker [as constructor] (C:\Users\sscott\Development\OntarioDarts.com\node_modules\tslint\lib\language\walker\skippableTokenAwareRuleWalker.js:11:16) 
at new EnableDisableRulesWalker (C:\Users\sscott\Development\OntarioDarts.com\node_modules\tslint\lib\enableDisableRules.js:13:16) 
at Linter.lint (C:\Users\sscott\Development\OntarioDarts.com\node_modules\tslint\lib\tslint.js:16:27) 
at C:\Users\sscott\Development\OntarioDarts.com\node_modules\gulp-tslint\index.js:96:34 
at respond (C:\Users\sscott\Development\OntarioDarts.com\node_modules\rcloader\index.js:73:7) 
at respond (C:\Users\sscott\Development\OntarioDarts.com\node_modules\rcfinder\index.js:140:7) 
at next (C:\Users\sscott\Development\OntarioDarts.com\node_modules\rcfinder\index.js:164:16) 
at nextTickCallbackWith0Args (node.js:433:9) 
at process._tickCallback (node.js:362:13) 

Я использую Windows, 10. У меня есть машинопись, tslint, проглатывать-машинопись и проглатывать-tslint.

Установленные версии:

├─┬ [email protected] 
│ └── [email protected] 
├─┬ [email protected] 
│ └─┬ [email protected] 
│ └─┬ [email protected] 
│  └─┬ [email protected] 
│  └── [email protected] 
├─┬ [email protected] 
│ └─┬ [email protected] 
│ └── [email protected] 
└── typescr[email protected] 

Глоток задача:

module.exports = function (gulp, PlugIns, Settings) { 
    return function() { 
     gulp.src([Settings.SourceFiles.TypeScript]) 
      .pipe(PlugIns.plumber()) 
      .pipe(PlugIns.debug()) 
      .pipe(PlugIns.typescript()) 

      .pipe(PlugIns.tslint({ 
       configuration: { 
        rules: { 
         "class-name": true, 
         "comment-format": [ 
          true, 
          "check-space", 
          "check-uppercase" 
         ], 
         "curly": true, 
         "eofline": true, 
         "indent": [ 
          true, 
          "tabs" 
         ], 
         "jsdoc-format": true, 
         "max-line-length": 100, 
         "no-unreachable": true, 
         "no-unused-expression": true, 
         "no-unused-variable": true, 
         "no-use-before-declare": true, 

         "one-line": [ 
          true, 
          "check-open-brace", 
          "check-catch", 
          "check-else", 
          "check-whitespace" 
         ], 
         "quotemark": [ 
          true, 
          "single", 
          "avoid-escape" 
         ], 
         "semicolon": true, 
         "switch-default": true, 

         "variable-name": [ 
          true, 
          "allow-trailing-underscore", 
          "ban-keywords" 
         ], 
         "whitespace": [ 
          true, 
          "check-branch", 
          "check-decl", 
          "check-operator", 
          "check-separator", 
          "check-type" 
         ] 
        } 
       } 
      })) 
      .pipe(PlugIns.tslint.report("stylish")) 
      .pipe(gulp.dest(Settings.Destination.TSCompiled)) 
     ; 
    } 
}; 

ответ

8

Эта ошибка часто возникает, если TSLint рассказана обработать файл, который не заканчивается в .ts или .tsx расширения. Я бы удостоверился, что вы случайно не отправляете файлы или файлы .js с другими расширениями. В будущем возможно, что файлы .js работают правильно, но сейчас их не будет.

Кроме того, я попытался запустить TSLint из командной строки с той же конфигурацией на нескольких ваших файлах. Если он работает неправильно, это может указывать на ошибку TSLint.

+0

Я изменил свой файл, чтобы попытаться обработать только один файл, который не удался аналогично с .ts и .tsx. Однако, как вы сказали, tslint работает из командной строки. Я зарегистрировал ошибку с gulp-tslint. https://github.com/panuhorsmalahti/gulp-tslint/issues/52 –

+1

Поскольку я не могу изменить свой последний комментарий сейчас из-за возраста, проблема с gulp-tslint была исправлена ​​и работает с более новыми версиями. –

+0

Спасибо за ответ! При использовании 'tslint src/ts/Person.ts' linting работал на меня. :) –

Смежные вопросы