diff --git a/README.md b/README.md index a2cc083..ac31eca 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,7 @@ Your `node_modules` folder should look like this: * `alwaysShowRuleFailuresAsWarnings` - always show rule failures as warnings, ignoring the severity configuration in the tslint.json configuration. * `disableNoUnusedVariableRule` - disable `no-unused-variable` rule. * `supressWhileTypeErrorsPresent` - supress tslint errors from being reported while other errors are present. + * `mockTypeScriptVersion` - force tslint to use the same version of TypeScript as this plugin. This will affect other plugins that require the typescript package. Here a configuration sample: @@ -53,7 +54,8 @@ Here a configuration sample: "ignoreDefinitionFiles": true, "configFile": "../tslint.json", "disableNoUnusedVariableRule": false, - "supressWhileTypeErrorsPresent": false + "supressWhileTypeErrorsPresent": false, + "mockTypeScriptVersion": false } ] } diff --git a/package.json b/package.json index 03f232a..c616cf2 100644 --- a/package.json +++ b/package.json @@ -17,10 +17,13 @@ "test": "tsc && tape out/test/**/*.spec.js", "lint": "tslint src/index.ts" }, - "dependencies": {}, + "dependencies": { + "mock-require": "^2.0.2" + }, "devDependencies": { "@types/node": "^7.0.8", "@types/tape": "^4.2.29", + "@types/mock-require": "^2.0.0", "tape": "^4.6.3", "tslint": "^5.2.0", "typescript": "^2.3.2", diff --git a/src/index.ts b/src/index.ts index a528cb8..159e041 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,7 @@ import * as ts_module from "../node_modules/typescript/lib/tsserverlibrary"; import * as tslint from 'tslint'; import * as path from 'path'; +import * as mockRequire from 'mock-require'; // Settings for the plugin section in tsconfig.json interface Settings { @@ -9,6 +10,7 @@ interface Settings { configFile?: string; disableNoUnusedVariableRule?: boolean // support to enable/disable the workaround for https://github.com/Microsoft/TypeScript/issues/15344 supressWhileTypeErrorsPresent: boolean; + mockTypeScriptVersion: boolean; } //TODO we "steal"" an error code with a registered code fix. 2515 = implement inherited abstract class @@ -16,6 +18,7 @@ const TSLINT_ERROR_CODE = 2515; function init(modules: { typescript: typeof ts_module }) { const ts = modules.typescript; + let tslint = require('tslint'); let codeFixActions = new Map>(); let registeredCodeFixes = false; @@ -63,6 +66,11 @@ function init(modules: { typescript: typeof ts_module }) { let config: Settings = fixRelativeConfigFilePath(info.config, info.project.getCurrentDirectory()); let configuration: tslint.Configuration.IConfigurationFile = null; + if(config.mockTypeScriptVersion) { + mockRequire('typescript', ts); + tslint = mockRequire.reRequire('tslint'); + } + // Set up decorator const proxy = Object.create(null) as ts.LanguageService; const oldLS = info.languageService;