From 19d6068d7f03791448fc416efc21dade419edfa0 Mon Sep 17 00:00:00 2001 From: Jay Anslow Date: Tue, 26 Apr 2016 22:14:04 +0100 Subject: [PATCH 01/20] Add `resolve` dependency (and custom typings) --- custom-typings/resolve.d.ts | 29 +++++++++++++++++++++++++++++ package.json | 1 + src/tsconfig.json | 1 + test/tsconfig.json | 1 + 4 files changed, 32 insertions(+) create mode 100644 custom-typings/resolve.d.ts diff --git a/custom-typings/resolve.d.ts b/custom-typings/resolve.d.ts new file mode 100644 index 00000000000..31ab1a0d164 --- /dev/null +++ b/custom-typings/resolve.d.ts @@ -0,0 +1,29 @@ +declare module "resolve" { + interface ResolveOptions { + basedir?: string; + extensions?: string[]; + paths?: string[]; + moduleDirectory?: string | string[]; + } + interface AsyncResolveOptions extends ResolveOptions { + package?: any; + readFile?: Function; + isFile?: (file: string, cb: Function) => void; + packageFilter?: Function; + pathFilter?: Function; + } + interface SyncResolveOptions extends ResolveOptions { + readFile?: Function; + isFile?: (file: string) => boolean; + packageFilter?: Function; + } + interface ResolveFunction { + (id: string, cb: (err: any, res: string, pkg: any) => void): void; + (id: string, opts: AsyncResolveOptions, cb: (err: any, res: string, pkg: any) => void): void; + sync(id: string, opts?: SyncResolveOptions): string; + isCore(pkg: any): any; + } + + const resolve: ResolveFunction; + export = resolve; +} diff --git a/package.json b/package.json index 9b26fb35333..8366a8415fd 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "glob": "^6.0.1", "optimist": "~0.6.0", "path-is-absolute": "^1.0.0", + "resolve": "^1.1.7", "underscore.string": "~3.1.1" }, "devDependencies": { diff --git a/src/tsconfig.json b/src/tsconfig.json index de8ab98f545..ed00f2e64f4 100644 --- a/src/tsconfig.json +++ b/src/tsconfig.json @@ -22,6 +22,7 @@ ], "files": [ "../custom-typings/path-is-absolute.d.ts", + "../custom-typings/resolve.d.ts", "../typings/colors/colors.d.ts", "../typings/diff/diff.d.ts", "../typings/findup-sync/findup-sync.d.ts", diff --git a/test/tsconfig.json b/test/tsconfig.json index 21d5b1f6914..9eb6193e4a5 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -21,6 +21,7 @@ ], "files": [ "../custom-typings/path-is-absolute.d.ts", + "../custom-typings/resolve.d.ts", "../typings/colors/colors.d.ts", "../typings/diff/diff.d.ts", "../typings/findup-sync/findup-sync.d.ts", From ac0f51e724ac559e77a1275b1ea4f431fcd96c6e Mon Sep 17 00:00:00 2001 From: Jay Anslow Date: Tue, 26 Apr 2016 22:30:02 +0100 Subject: [PATCH 02/20] Use resolve instead of require in resolveConfigurationPaths Fixes #1171 --- src/configuration.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/configuration.ts b/src/configuration.ts index e7e65ca41ec..7c79113fd6f 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -19,6 +19,7 @@ import * as fs from "fs"; import * as path from "path"; import * as findup from "findup-sync"; import * as pathIsAbsolute from "path-is-absolute"; +import * as resolve from "resolve"; import {arrayify, objectify, stripComments} from "./utils"; @@ -173,7 +174,7 @@ function resolveConfigurationPath(relativeFilePath: string, relativeTo?: string) resolvedPath = getRelativePath(relativeFilePath, relativeTo); } else { try { - resolvedPath = require.resolve(relativeFilePath); + resolvedPath = resolve.sync(relativeFilePath, { basedir: relativeTo }); } catch (err) { throw new Error(`Invalid "extends" configuration value - could not require "${relativeFilePath}". ` + "Review the Node lookup algorithm (https://nodejs.org/api/modules.html#modules_all_together) " + From 49d6b1ed3df479ecf33bba908327411cfc3c39bd Mon Sep 17 00:00:00 2001 From: Jay Anslow Date: Wed, 27 Apr 2016 02:33:55 +0100 Subject: [PATCH 03/20] Simplify resolveConfigurationPath `resolve` can handle relative and absolute links. --- src/configuration.ts | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/src/configuration.ts b/src/configuration.ts index 7c79113fd6f..54cf2806890 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -18,7 +18,6 @@ import * as fs from "fs"; import * as path from "path"; import * as findup from "findup-sync"; -import * as pathIsAbsolute from "path-is-absolute"; import * as resolve from "resolve"; import {arrayify, objectify, stripComments} from "./utils"; @@ -167,22 +166,14 @@ export function loadConfigurationFromPath(configFilePath: string): IConfiguratio * @var relativeFilePath Relative path or package name (tslint-config-X) or package short name (X) */ function resolveConfigurationPath(relativeFilePath: string, relativeTo?: string) { - let resolvedPath: string; - if (pathIsAbsolute(relativeFilePath)) { - resolvedPath = relativeFilePath; - } else if (relativeFilePath.indexOf(".") === 0) { - resolvedPath = getRelativePath(relativeFilePath, relativeTo); - } else { - try { - resolvedPath = resolve.sync(relativeFilePath, { basedir: relativeTo }); - } catch (err) { - throw new Error(`Invalid "extends" configuration value - could not require "${relativeFilePath}". ` + - "Review the Node lookup algorithm (https://nodejs.org/api/modules.html#modules_all_together) " + - "for the approximate method TSLint uses to find the referenced configuration file."); - } + const basedir = relativeTo || process.cwd(); + try { + return resolve.sync(relativeFilePath, { basedir }); + } catch (err) { + throw new Error(`Invalid "extends" configuration value - could not require "${relativeFilePath}". ` + + "Review the Node lookup algorithm (https://nodejs.org/api/modules.html#modules_all_together) " + + "for the approximate method TSLint uses to find the referenced configuration file."); } - - return resolvedPath; } export function extendConfigurationFile(config: IConfigurationFile, baseConfig: IConfigurationFile): IConfigurationFile { From 99110fe59110ef16eb4be06fe10585b4891e864d Mon Sep 17 00:00:00 2001 From: Jay Anslow Date: Wed, 27 Apr 2016 02:37:58 +0100 Subject: [PATCH 04/20] path-is-absolute is no longer needed. --- custom-typings/path-is-absolute.d.ts | 6 ------ package.json | 1 - src/tsconfig.json | 1 - test/tsconfig.json | 1 - 4 files changed, 9 deletions(-) delete mode 100644 custom-typings/path-is-absolute.d.ts diff --git a/custom-typings/path-is-absolute.d.ts b/custom-typings/path-is-absolute.d.ts deleted file mode 100644 index abd6483b38c..00000000000 --- a/custom-typings/path-is-absolute.d.ts +++ /dev/null @@ -1,6 +0,0 @@ - -declare module "path-is-absolute" { - namespace pathIsAbsolute {} - function pathIsAbsolute(path: string): boolean; - export = pathIsAbsolute; -} diff --git a/package.json b/package.json index 8366a8415fd..3e44856d190 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,6 @@ "findup-sync": "~0.3.0", "glob": "^6.0.1", "optimist": "~0.6.0", - "path-is-absolute": "^1.0.0", "resolve": "^1.1.7", "underscore.string": "~3.1.1" }, diff --git a/src/tsconfig.json b/src/tsconfig.json index ed00f2e64f4..dd1fb23b28c 100644 --- a/src/tsconfig.json +++ b/src/tsconfig.json @@ -21,7 +21,6 @@ "./test/**/*.ts" ], "files": [ - "../custom-typings/path-is-absolute.d.ts", "../custom-typings/resolve.d.ts", "../typings/colors/colors.d.ts", "../typings/diff/diff.d.ts", diff --git a/test/tsconfig.json b/test/tsconfig.json index 9eb6193e4a5..16d1ee67b7d 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -20,7 +20,6 @@ "./rule-tester/*.ts" ], "files": [ - "../custom-typings/path-is-absolute.d.ts", "../custom-typings/resolve.d.ts", "../typings/colors/colors.d.ts", "../typings/diff/diff.d.ts", From eb4dde755bf16d94b34bd111b27a1462498128e8 Mon Sep 17 00:00:00 2001 From: Jay Anslow Date: Wed, 27 Apr 2016 10:44:15 +0100 Subject: [PATCH 05/20] Install test packages in subdirectory, so they aren't in the scope of the main tslint binary --- package.json | 2 -- test/config/package.json | 8 ++++++++ 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 test/config/package.json diff --git a/package.json b/package.json index 3e44856d190..3fbd8520615 100644 --- a/package.json +++ b/package.json @@ -40,8 +40,6 @@ "grunt-tslint": "latest", "mocha": "^2.2.5", "tslint": "latest", - "tslint-test-config": "./test/external/tslint-test-config", - "tslint-test-custom-rules": "./test/external/tslint-test-custom-rules", "typescript": "latest" }, "peerDependencies": { diff --git a/test/config/package.json b/test/config/package.json new file mode 100644 index 00000000000..7fb1b7cb1cb --- /dev/null +++ b/test/config/package.json @@ -0,0 +1,8 @@ +{ + "name": "tslint-test-configs", + "version": "0.0.1", + "dependencies": { + "tslint-test-config": "../external/tslint-test-config", + "tslint-test-custom-rules": "../external/tslint-test-custom-rules" + } +} From 40dece17b52441e6eacbfbf49ae8a8800e0be2aa Mon Sep 17 00:00:00 2001 From: Jay Anslow Date: Wed, 27 Apr 2016 11:13:25 +0100 Subject: [PATCH 06/20] Run `npm install` in test config directory to install test packages. --- Gruntfile.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Gruntfile.js b/Gruntfile.js index a32081d2b83..9552432f9dc 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -27,6 +27,13 @@ module.exports = function (grunt) { }, run: { + installTestDeps: { + cmd: "npm", + args: ["install"], + options: { + cwd: "./test/config" + } + }, testBin: { cmd: "./test/check-bin.sh", options: {quiet: Infinity} @@ -87,6 +94,7 @@ module.exports = function (grunt) { ]); grunt.registerTask("test", [ "clean:test", + "run:installTestDeps", "ts:test", "tslint:test", "mochaTest", From f74bd30e0f0c921d6ec077db1dded005a22af176 Mon Sep 17 00:00:00 2001 From: Jay Anslow Date: Wed, 27 Apr 2016 11:15:27 +0100 Subject: [PATCH 07/20] Fix code style issue --- Gruntfile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gruntfile.js b/Gruntfile.js index 9552432f9dc..cd0225e5a48 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -31,7 +31,7 @@ module.exports = function (grunt) { cmd: "npm", args: ["install"], options: { - cwd: "./test/config" + cwd: "./test/config" } }, testBin: { From fa0b9472e129ab493ed28baf04eadd52e482a64d Mon Sep 17 00:00:00 2001 From: Jay Anslow Date: Wed, 27 Apr 2016 22:46:16 +0100 Subject: [PATCH 08/20] Add dev dependency on npm for grunt run:installTestDeps task --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 3fbd8520615..cb962008d08 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "grunt-ts": "^5.1.0", "grunt-tslint": "latest", "mocha": "^2.2.5", + "npm": "^3.8.7", "tslint": "latest", "typescript": "latest" }, From fdb7fd89925ac8305a2f79970a6f8d3dc33e5f4f Mon Sep 17 00:00:00 2001 From: Jay Anslow Date: Wed, 27 Apr 2016 22:51:13 +0100 Subject: [PATCH 09/20] Revert "Add dev dependency on npm for grunt run:installTestDeps task" This reverts commit fa0b9472e129ab493ed28baf04eadd52e482a64d. --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index cb962008d08..3fbd8520615 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,6 @@ "grunt-ts": "^5.1.0", "grunt-tslint": "latest", "mocha": "^2.2.5", - "npm": "^3.8.7", "tslint": "latest", "typescript": "latest" }, From 566368327b30173195344f8ab834df56fbfdcc10 Mon Sep 17 00:00:00 2001 From: Jay Anslow Date: Wed, 27 Apr 2016 22:57:31 +0100 Subject: [PATCH 10/20] Replace run:installTestDeps task with npm-command:test --- Gruntfile.js | 16 +++++++++------- package.json | 1 + 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index cd0225e5a48..3ff5e815ecc 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -27,13 +27,6 @@ module.exports = function (grunt) { }, run: { - installTestDeps: { - cmd: "npm", - args: ["install"], - options: { - cwd: "./test/config" - } - }, testBin: { cmd: "./test/check-bin.sh", options: {quiet: Infinity} @@ -75,6 +68,14 @@ module.exports = function (grunt) { test: { tsconfig: "test/tsconfig.json" } + }, + + 'npm-command': { + test: { + options: { + cwd: './test/config' + } + } } }); @@ -85,6 +86,7 @@ module.exports = function (grunt) { grunt.loadNpmTasks("grunt-run"); grunt.loadNpmTasks("grunt-tslint"); grunt.loadNpmTasks("grunt-ts"); + grunt.loadNpmTasks("grunt-npm-command"); // register custom tasks grunt.registerTask("core", [ diff --git a/package.json b/package.json index 3fbd8520615..13ca3e9af66 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "grunt-contrib-clean": "^0.6.0", "grunt-jscs": "^1.8.0", "grunt-mocha-test": "^0.12.7", + "grunt-npm-command": "^0.1.1", "grunt-run": "^0.3.0", "grunt-ts": "^5.1.0", "grunt-tslint": "latest", From 5f787b6c5e712eade39ef734bc4809818139e9a6 Mon Sep 17 00:00:00 2001 From: Jay Anslow Date: Wed, 27 Apr 2016 23:01:02 +0100 Subject: [PATCH 11/20] Fix lint errors in Gruntfile --- Gruntfile.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 3ff5e815ecc..6aae526aece 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -70,10 +70,10 @@ module.exports = function (grunt) { } }, - 'npm-command': { + "npm-command": { test: { options: { - cwd: './test/config' + cwd: "./test/config" } } } @@ -96,7 +96,7 @@ module.exports = function (grunt) { ]); grunt.registerTask("test", [ "clean:test", - "run:installTestDeps", + "npm-command:test", "ts:test", "tslint:test", "mochaTest", From 947c0f028368198c2bfb9fb2feecd759695bd8e2 Mon Sep 17 00:00:00 2001 From: Jay Anslow Date: Thu, 28 Apr 2016 00:58:37 +0100 Subject: [PATCH 12/20] Resolve config file relative to the cwd if it can't be found relative to the parent config --- src/configuration.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/configuration.ts b/src/configuration.ts index 54cf2806890..116850656e0 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -170,9 +170,13 @@ function resolveConfigurationPath(relativeFilePath: string, relativeTo?: string) try { return resolve.sync(relativeFilePath, { basedir }); } catch (err) { - throw new Error(`Invalid "extends" configuration value - could not require "${relativeFilePath}". ` + - "Review the Node lookup algorithm (https://nodejs.org/api/modules.html#modules_all_together) " + - "for the approximate method TSLint uses to find the referenced configuration file."); + try { + return require.resolve(relativeFilePath); + } catch (err) { + throw new Error(`Invalid "extends" configuration value - could not require "${relativeFilePath}". ` + + "Review the Node lookup algorithm (https://nodejs.org/api/modules.html#modules_all_together) " + + "for the approximate method TSLint uses to find the referenced configuration file."); + } } } From 4cb1fdd16b019e34cb9223e5c17c26366dff50eb Mon Sep 17 00:00:00 2001 From: Jay Anslow Date: Thu, 28 Apr 2016 01:18:58 +0100 Subject: [PATCH 13/20] Make rules in tslint-test-custom-rules package valid rules (copied from noFailRule) --- .../rules/ruleOneRule.js | 27 +++++++++++++++++++ .../rules/ruleThreeRule.js | 27 +++++++++++++++++++ .../rules/ruleTwoRule.js | 27 +++++++++++++++++++ 3 files changed, 81 insertions(+) diff --git a/test/external/tslint-test-custom-rules/rules/ruleOneRule.js b/test/external/tslint-test-custom-rules/rules/ruleOneRule.js index e69de29bb2d..1d2ff62d1af 100644 --- a/test/external/tslint-test-custom-rules/rules/ruleOneRule.js +++ b/test/external/tslint-test-custom-rules/rules/ruleOneRule.js @@ -0,0 +1,27 @@ +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Lint = require("tslint/lib/lint"); +var Rule = (function (_super) { + __extends(Rule, _super); + function Rule() { + _super.apply(this, arguments); + } + Rule.prototype.apply = function (sourceFile) { + return this.applyWithWalker(new NoFailWalker(sourceFile, this.getOptions())); + }; + return Rule; +})(Lint.Rules.AbstractRule); +exports.Rule = Rule; +var NoFailWalker = (function (_super) { + __extends(NoFailWalker, _super); + function NoFailWalker() { + _super.apply(this, arguments); + } + NoFailWalker.prototype.visitSourceFile = function (node) { + // yay, no failures! + }; + return NoFailWalker; +})(Lint.RuleWalker); diff --git a/test/external/tslint-test-custom-rules/rules/ruleThreeRule.js b/test/external/tslint-test-custom-rules/rules/ruleThreeRule.js index e69de29bb2d..1d2ff62d1af 100644 --- a/test/external/tslint-test-custom-rules/rules/ruleThreeRule.js +++ b/test/external/tslint-test-custom-rules/rules/ruleThreeRule.js @@ -0,0 +1,27 @@ +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Lint = require("tslint/lib/lint"); +var Rule = (function (_super) { + __extends(Rule, _super); + function Rule() { + _super.apply(this, arguments); + } + Rule.prototype.apply = function (sourceFile) { + return this.applyWithWalker(new NoFailWalker(sourceFile, this.getOptions())); + }; + return Rule; +})(Lint.Rules.AbstractRule); +exports.Rule = Rule; +var NoFailWalker = (function (_super) { + __extends(NoFailWalker, _super); + function NoFailWalker() { + _super.apply(this, arguments); + } + NoFailWalker.prototype.visitSourceFile = function (node) { + // yay, no failures! + }; + return NoFailWalker; +})(Lint.RuleWalker); diff --git a/test/external/tslint-test-custom-rules/rules/ruleTwoRule.js b/test/external/tslint-test-custom-rules/rules/ruleTwoRule.js index e69de29bb2d..1d2ff62d1af 100644 --- a/test/external/tslint-test-custom-rules/rules/ruleTwoRule.js +++ b/test/external/tslint-test-custom-rules/rules/ruleTwoRule.js @@ -0,0 +1,27 @@ +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Lint = require("tslint/lib/lint"); +var Rule = (function (_super) { + __extends(Rule, _super); + function Rule() { + _super.apply(this, arguments); + } + Rule.prototype.apply = function (sourceFile) { + return this.applyWithWalker(new NoFailWalker(sourceFile, this.getOptions())); + }; + return Rule; +})(Lint.Rules.AbstractRule); +exports.Rule = Rule; +var NoFailWalker = (function (_super) { + __extends(NoFailWalker, _super); + function NoFailWalker() { + _super.apply(this, arguments); + } + NoFailWalker.prototype.visitSourceFile = function (node) { + // yay, no failures! + }; + return NoFailWalker; +})(Lint.RuleWalker); From f9a07d1fa0d4fb2359bce1d8d232ad43d5d3263b Mon Sep 17 00:00:00 2001 From: Jay Anslow Date: Thu, 28 Apr 2016 01:21:51 +0100 Subject: [PATCH 14/20] Add CLI test with a relative extend config --- test/check-bin.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/check-bin.sh b/test/check-bin.sh index ad84ee45aae..254e0658ad0 100755 --- a/test/check-bin.sh +++ b/test/check-bin.sh @@ -20,7 +20,7 @@ expectOut () { msg=$3 nodeV=`node -v` - + # if Node 0.10.*, node will sometimes exit with status 8 when an error is thrown if [[ $expect != $actual || $nodeV == v0.10.* && $expect == 1 && $actual == 8 ]] ; then echo "$msg: expected $expect got $actual" @@ -70,6 +70,10 @@ expectOut $? 0 "tslint with with -r pointing to custom rules did not find lint f ./bin/tslint -c test/config/tslint-almost-empty.json src/tslint.ts expectOut $? 0 "-c relative path without ./ did not work" +# make sure calling tslint with a config file which extends a package relative to the config file works +./bin/tslint -c test/config/tslint-extends-package-no-mod.json src/tslint.ts +expectOut $? 0 "tslint (with config file extending relative package) did not work" + # make sure tslint --init generates a file cd ./bin if [ -f tslint.json ]; then From b4b2e1a7a6f99ef37a007f71a0adfb1d3f37a059 Mon Sep 17 00:00:00 2001 From: Jay Anslow Date: Thu, 28 Apr 2016 22:19:54 +0100 Subject: [PATCH 15/20] Add test config package And install it as a dev dependency --- package.json | 1 + test/external/tslint-test-config-non-relative/index.js | 0 test/external/tslint-test-config-non-relative/package.json | 7 +++++++ test/external/tslint-test-config-non-relative/tslint.json | 7 +++++++ 4 files changed, 15 insertions(+) create mode 100644 test/external/tslint-test-config-non-relative/index.js create mode 100644 test/external/tslint-test-config-non-relative/package.json create mode 100644 test/external/tslint-test-config-non-relative/tslint.json diff --git a/package.json b/package.json index 13ca3e9af66..696249bb297 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "grunt-tslint": "latest", "mocha": "^2.2.5", "tslint": "latest", + "tslint-test-config-non-relative": "file:test/external/tslint-test-config-non-relative", "typescript": "latest" }, "peerDependencies": { diff --git a/test/external/tslint-test-config-non-relative/index.js b/test/external/tslint-test-config-non-relative/index.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/external/tslint-test-config-non-relative/package.json b/test/external/tslint-test-config-non-relative/package.json new file mode 100644 index 00000000000..bbeea219c6a --- /dev/null +++ b/test/external/tslint-test-config-non-relative/package.json @@ -0,0 +1,7 @@ +{ + "name": "tslint-test-config-non-relative", + "description": "A test package with a tslint config which is installed in the tslint.", + "version": "0.0.1", + "main": "index.js", + "scripts": {} +} diff --git a/test/external/tslint-test-config-non-relative/tslint.json b/test/external/tslint-test-config-non-relative/tslint.json new file mode 100644 index 00000000000..2cf73c5a02d --- /dev/null +++ b/test/external/tslint-test-config-non-relative/tslint.json @@ -0,0 +1,7 @@ +{ + "extends": "tslint-test-custom-rules", + "rules": { + "rule-two": true, + "rule-four": true + } +} From a439cac37b5bab121471c0516eb85be0b9fe741b Mon Sep 17 00:00:00 2001 From: Jay Anslow Date: Thu, 28 Apr 2016 22:21:54 +0100 Subject: [PATCH 16/20] Add CLI test for extending a package which is installed in tslint. --- test/check-bin.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/check-bin.sh b/test/check-bin.sh index 254e0658ad0..eb831206ba8 100755 --- a/test/check-bin.sh +++ b/test/check-bin.sh @@ -74,6 +74,14 @@ expectOut $? 0 "-c relative path without ./ did not work" ./bin/tslint -c test/config/tslint-extends-package-no-mod.json src/tslint.ts expectOut $? 0 "tslint (with config file extending relative package) did not work" +# check that a tslint file (outside of the resolution path of the tslint package) can resolve a package that is +# installed as a dependency of tslint. See palantir/tslint#1172 for details. +tmpDir=$(mktemp -d) +echo "{ \"extends\": \"tslint-test-config-non-relative\" }" > $tmpDir/tslint.json +./bin/tslint -c $tmpDir/tslint.json src/tslint.ts +expectOut $? 0 "tslint (with config file extending package in tslint scope) did not work" +rm -r $tmpDir + # make sure tslint --init generates a file cd ./bin if [ -f tslint.json ]; then From b35f877e76427357a90d4de4d63872612af098e3 Mon Sep 17 00:00:00 2001 From: Jay Anslow Date: Thu, 28 Apr 2016 22:35:38 +0100 Subject: [PATCH 17/20] Make test packages private --- test/external/tslint-test-config-non-relative/package.json | 1 + test/external/tslint-test-config/package.json | 1 + test/external/tslint-test-custom-rules/package.json | 1 + 3 files changed, 3 insertions(+) diff --git a/test/external/tslint-test-config-non-relative/package.json b/test/external/tslint-test-config-non-relative/package.json index bbeea219c6a..d15fa25d533 100644 --- a/test/external/tslint-test-config-non-relative/package.json +++ b/test/external/tslint-test-config-non-relative/package.json @@ -3,5 +3,6 @@ "description": "A test package with a tslint config which is installed in the tslint.", "version": "0.0.1", "main": "index.js", + "private": true, "scripts": {} } diff --git a/test/external/tslint-test-config/package.json b/test/external/tslint-test-config/package.json index a6187cf5384..f41dfa4fd9a 100644 --- a/test/external/tslint-test-config/package.json +++ b/test/external/tslint-test-config/package.json @@ -2,5 +2,6 @@ "name": "tslint-test-config", "version": "0.0.1", "main": "index.js", + "private": true, "scripts": {} } diff --git a/test/external/tslint-test-custom-rules/package.json b/test/external/tslint-test-custom-rules/package.json index 811f867aba1..bc85751c874 100644 --- a/test/external/tslint-test-custom-rules/package.json +++ b/test/external/tslint-test-custom-rules/package.json @@ -1,6 +1,7 @@ { "name": "tslint-test-custom-rules", "version": "0.0.1", + "private": true, "main": "tslint.json", "scripts": {} } From 863794a550e3daa5bece955c0ebd538e0178b89d Mon Sep 17 00:00:00 2001 From: Jay Anslow Date: Thu, 28 Apr 2016 22:38:54 +0100 Subject: [PATCH 18/20] Fix entry point of test packages --- test/external/tslint-test-config-non-relative/package.json | 2 +- test/external/tslint-test-config/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/external/tslint-test-config-non-relative/package.json b/test/external/tslint-test-config-non-relative/package.json index d15fa25d533..75065e3be61 100644 --- a/test/external/tslint-test-config-non-relative/package.json +++ b/test/external/tslint-test-config-non-relative/package.json @@ -2,7 +2,7 @@ "name": "tslint-test-config-non-relative", "description": "A test package with a tslint config which is installed in the tslint.", "version": "0.0.1", - "main": "index.js", "private": true, + "main": "tslint.json", "scripts": {} } diff --git a/test/external/tslint-test-config/package.json b/test/external/tslint-test-config/package.json index f41dfa4fd9a..207f1aeeb86 100644 --- a/test/external/tslint-test-config/package.json +++ b/test/external/tslint-test-config/package.json @@ -1,7 +1,7 @@ { "name": "tslint-test-config", "version": "0.0.1", - "main": "index.js", "private": true, + "main": "tslint.json", "scripts": {} } From d4f95dedec33bc4725e1a438f2f9e1fb6face8f6 Mon Sep 17 00:00:00 2001 From: Jay Anslow Date: Thu, 28 Apr 2016 22:39:13 +0100 Subject: [PATCH 19/20] Simplify non-relative test package --- test/external/tslint-test-config-non-relative/tslint.json | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/test/external/tslint-test-config-non-relative/tslint.json b/test/external/tslint-test-config-non-relative/tslint.json index 2cf73c5a02d..fcaed86a61e 100644 --- a/test/external/tslint-test-config-non-relative/tslint.json +++ b/test/external/tslint-test-config-non-relative/tslint.json @@ -1,7 +1,5 @@ { - "extends": "tslint-test-custom-rules", - "rules": { - "rule-two": true, - "rule-four": true - } + "rules": { + "class-name": true + } } From 41cf9346c0dcffa7ce4f00d39433aa05c9635661 Mon Sep 17 00:00:00 2001 From: Jay Anslow Date: Thu, 28 Apr 2016 22:54:52 +0100 Subject: [PATCH 20/20] Add unit test for loadConfigurationFromPath with configs outside of the tslint require path. --- test/configurationTests.ts | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/test/configurationTests.ts b/test/configurationTests.ts index 3736d8585cb..b17a294408b 100644 --- a/test/configurationTests.ts +++ b/test/configurationTests.ts @@ -14,6 +14,8 @@ * limitations under the License. */ +import * as os from "os"; +import * as path from "path"; import * as fs from "fs"; import {IConfigurationFile, extendConfigurationFile, loadConfigurationFromPath} from "../src/configuration"; @@ -83,6 +85,35 @@ describe("Configuration", () => { }); }); + describe("with config not relative to tslint", () => { + let tmpfile: string; + beforeEach(() => { + for (let i = 0; i < 5; i++) { + const attempt = path.join(os.tmpdir(), `tslint.test${Math.round(Date.now() * Math.random())}.json`); + if (!fs.existsSync(tmpfile)) { + tmpfile = attempt; + break; + } + } + if (tmpfile === undefined) { + throw new Error("Couldn't create temp file"); + } + }); + afterEach(() => { + if (tmpfile !== undefined) { + fs.unlinkSync(tmpfile); + } + }); + it("extends with package installed relative to tslint", () => { + fs.writeFileSync(tmpfile, JSON.stringify({ extends: "tslint-test-config-non-relative" })); + let config = loadConfigurationFromPath(tmpfile); + assert.deepEqual(config.rules, { + "class-name": true, + }); + }); + }); + + it("extends with package two levels (and relative path in rulesDirectory)", () => { let config = loadConfigurationFromPath("./test/config/tslint-extends-package-two-levels.json");