Skip to content

Commit 0166da3

Browse files
Replace grunt-tslint with direct calling to tslint (#2954)
Some rules in our tslint.json require passing `--type-check` flag to `tslint` executable. However grunt-tslint does not support it. So remove the `grunt-tslint` and spawn the `tslint` via npm script. Add the new `tslint` script, so now the project can be linted by calling: * grunt lint * grunt tslint:build /for backwards compatibility/ * npm run tslint Fix the errors that are received after passing `--type-check` flag. Disable all linter errors for all automatically generated files (for messages).
1 parent 6cd4304 commit 0166da3

File tree

4 files changed

+40
-46
lines changed

4 files changed

+40
-46
lines changed

Gruntfile.js

+14-20
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
var now = new Date().toISOString();
1+
const childProcess = require("child_process");
2+
const now = new Date().toISOString();
23

34
function shallowCopy(obj) {
45
var result = {};
5-
Object.keys(obj).forEach(function(key) {
6+
Object.keys(obj).forEach(function (key) {
67
result[key] = obj[key];
78
});
89
return result;
@@ -11,10 +12,10 @@ function shallowCopy(obj) {
1112
var travis = process.env["TRAVIS"];
1213
var buildNumber = process.env["PACKAGE_VERSION"] || process.env["BUILD_NUMBER"] || "non-ci";
1314

14-
module.exports = function(grunt) {
15+
module.exports = function (grunt) {
1516
var path = require("path");
1617
var commonLibNodeModules = path.join("lib", "common", "node_modules");
17-
if(require("fs").existsSync(commonLibNodeModules)) {
18+
if (require("fs").existsSync(commonLibNodeModules)) {
1819
grunt.file.delete(commonLibNodeModules);
1920
}
2021
grunt.file.write(path.join("lib", "common", ".d.ts"), "");
@@ -50,17 +51,6 @@ module.exports = function(grunt) {
5051
},
5152
},
5253

53-
tslint: {
54-
build: {
55-
files: {
56-
src: ["lib/**/*.ts", "test/**/*.ts", "!lib/common/node_modules/**/*.ts", "!lib/common/messages/**/*.ts", "lib/common/test/unit-tests/**/*.ts", "definitions/**/*.ts", "!lib/**/*.d.ts" , "!test/**/*.d.ts"]
57-
},
58-
options: {
59-
configuration: grunt.file.readJSON("./tslint.json")
60-
}
61-
}
62-
},
63-
6454
watch: {
6555
devall: {
6656
files: ["lib/**/*.ts", 'test/**/*.ts', "!lib/common/node_modules/**/*.ts", "!lib/common/messages/**/*.ts"],
@@ -96,7 +86,7 @@ module.exports = function(grunt) {
9686
command: "npm pack",
9787
options: {
9888
execOptions: {
99-
env: (function() {
89+
env: (function () {
10090
var env = shallowCopy(process.env);
10191
env["NATIVESCRIPT_SKIP_POSTINSTALL_TASKS"] = "1";
10292
return env;
@@ -145,7 +135,7 @@ module.exports = function(grunt) {
145135
grunt.loadNpmTasks("grunt-ts");
146136
grunt.loadNpmTasks("grunt-tslint");
147137

148-
grunt.registerTask("set_package_version", function(version) {
138+
grunt.registerTask("set_package_version", function (version) {
149139
var buildVersion = version !== undefined ? version : buildNumber;
150140
if (process.env["BUILD_CAUSE_GHPRBCAUSE"]) {
151141
buildVersion = "PR" + buildVersion;
@@ -154,16 +144,20 @@ module.exports = function(grunt) {
154144
var packageJson = grunt.file.readJSON("package.json");
155145
var versionParts = packageJson.version.split("-");
156146
if (process.env["RELEASE_BUILD"]) {
157-
// HACK - excluded until 1.0.0 release or we refactor our project infrastructure (whichever comes first)
158-
// packageJson.version = versionParts[0];
147+
// HACK - excluded until 1.0.0 release or we refactor our project infrastructure (whichever comes first)
148+
// packageJson.version = versionParts[0];
159149
} else {
160150
versionParts[1] = buildVersion;
161151
packageJson.version = versionParts.join("-");
162152
}
163153
grunt.file.write("package.json", JSON.stringify(packageJson, null, " "));
164154
});
165155

166-
grunt.registerTask("enableScripts", function(enable) {
156+
grunt.registerTask("tslint:build", function (version) {
157+
childProcess.execSync("npm run tslint", { stdio: "inherit" });
158+
});
159+
160+
grunt.registerTask("enableScripts", function (enable) {
167161
var enableTester = /false/i;
168162
var newScriptsAttr = !enableTester.test(enable) ? "scripts" : "skippedScripts";
169163
var packageJson = grunt.file.readJSON("package.json");

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"preuninstall": "node preuninstall.js",
1616
"mocha": "node test-scripts/mocha.js",
1717
"tsc": "tsc",
18+
"tslint": "tslint -p tsconfig.json --type-check",
1819
"test-watch": "node ./dev/tsc-to-mocha-watch.js"
1920
},
2021
"repository": {
@@ -97,7 +98,6 @@
9798
"grunt-contrib-watch": "1.0.0",
9899
"grunt-shell": "1.3.0",
99100
"grunt-ts": "6.0.0-beta.16",
100-
"grunt-tslint": "5.0.1",
101101
"istanbul": "0.4.5",
102102
"mocha": "3.1.2",
103103
"should": "7.0.2",

test/stubs.ts

+24-24
Original file line numberDiff line numberDiff line change
@@ -245,30 +245,6 @@ export class ProjectDataStub implements IProjectData {
245245
}
246246
}
247247

248-
export class PlatformsDataStub extends EventEmitter implements IPlatformsData {
249-
public platformsNames: string[];
250-
251-
public getPlatformData(platform: string, projectData: IProjectData): IPlatformData {
252-
return {
253-
frameworkPackageName: "",
254-
platformProjectService: new PlatformProjectServiceStub(),
255-
emulatorServices: undefined,
256-
projectRoot: "",
257-
normalizedPlatformName: "",
258-
appDestinationDirectoryPath: "",
259-
deviceBuildOutputPath: "",
260-
getValidPackageNames: (buildOptions: { isForDevice?: boolean, isReleaseBuild?: boolean }) => [],
261-
frameworkFilesExtensions: [],
262-
relativeToFrameworkConfigurationFilePath: "",
263-
fastLivesyncFileExtensions: []
264-
};
265-
}
266-
267-
public get availablePlatforms(): any {
268-
return undefined;
269-
}
270-
}
271-
272248
export class PlatformProjectServiceStub extends EventEmitter implements IPlatformProjectService {
273249
getPlatformData(projectData: IProjectData): IPlatformData {
274250
return {
@@ -362,6 +338,30 @@ export class PlatformProjectServiceStub extends EventEmitter implements IPlatfor
362338
}
363339
}
364340

341+
export class PlatformsDataStub extends EventEmitter implements IPlatformsData {
342+
public platformsNames: string[];
343+
344+
public getPlatformData(platform: string, projectData: IProjectData): IPlatformData {
345+
return {
346+
frameworkPackageName: "",
347+
platformProjectService: new PlatformProjectServiceStub(),
348+
emulatorServices: undefined,
349+
projectRoot: "",
350+
normalizedPlatformName: "",
351+
appDestinationDirectoryPath: "",
352+
deviceBuildOutputPath: "",
353+
getValidPackageNames: (buildOptions: { isForDevice?: boolean, isReleaseBuild?: boolean }) => [],
354+
frameworkFilesExtensions: [],
355+
relativeToFrameworkConfigurationFilePath: "",
356+
fastLivesyncFileExtensions: []
357+
};
358+
}
359+
360+
public get availablePlatforms(): any {
361+
return undefined;
362+
}
363+
}
364+
365365
export class ProjectDataService implements IProjectDataService {
366366
getNSValue(propertyName: string): any {
367367
return {};

0 commit comments

Comments
 (0)