Skip to content

Commit

Permalink
feat(stark-build): tslintLoader - disable typecheck rules to remove w…
Browse files Browse the repository at this point in the history
…arnings while typeCheck is false

- update inline documentation

ISSUES CLOSED: #405
  • Loading branch information
carlo-nomes committed Apr 4, 2019
1 parent 0903bc9 commit b38aa7f
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 21 deletions.
43 changes: 43 additions & 0 deletions packages/stark-build/config/build-utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const ts = require("typescript");
const path = require("path");
const fs = require("fs");
const os = require("os");
var crypto = require("crypto");

const helpers = require("./helpers");
const ngCliUtils = require("./ng-cli-utils");

Expand Down Expand Up @@ -90,6 +93,15 @@ function getEnvironmentFile(environment) {
}
}

/**
* Gets the value at `path` of `object`. If the resolved value is
* `undefined`, the `defaultValue` is returned in its place.
*
* @param {Object} obj The object to query.
* @param {string|Array} path The path of the property to get.
* @param {*} [defaultValue] The value returned for `undefined` resolved values.
* @returns {*} Returns the resolved value.
*/
function get(obj, path, defaultValue) {
let args;
if (typeof path === "string") {
Expand All @@ -107,9 +119,40 @@ function get(obj, path, defaultValue) {
return obj;
}

/**
* Makes a new tslint.json file that extends the default (tslint.json) and disables all the tslint rules that require typechecking
* @see FIXME on webpack-partial.common.js (module.exports().module.rules)
*
* @param {string} tslintConfig The path to the projects tslint.json
* @return {string} Returns the path to the temporary tslint configuration for tslint-loader
*/
function getFixedTSLintConfig(tslintConfig) {
const tslintConfigPath = helpers.root(tslintConfig);

const noTypeCheckTSLintConfig = fs
.readFileSync(helpers.rootStark("config/tslint-disabled-typecheck-rules.json"), "utf8")
.replace(/TSLINT_CONFIG_PLACEHOLDER/, tslintConfigPath);

const contentHash = crypto
.createHash("md5")
.update(noTypeCheckTSLintConfig)
.digest("hex");

const noTypeCheckTSLintConfigPath = path.resolve(os.tmpdir(), `national-bank-belgium_stark-build_tslint-${contentHash}.json`);

// check if file already exists before writing it
if (!fs.existsSync(noTypeCheckTSLintConfigPath)) {
console.log(`Writing TSLint configuration to ${noTypeCheckTSLintConfigPath}`);
fs.writeFileSync(noTypeCheckTSLintConfigPath, noTypeCheckTSLintConfig, "utf8");
}

return noTypeCheckTSLintConfigPath;
}

exports.ANGULAR_APP_CONFIG = ANGULAR_APP_CONFIG;
exports.DEFAULT_METADATA = DEFAULT_METADATA;
exports.getEnvironmentFile = getEnvironmentFile;
exports.readTsConfig = readTsConfig;
exports.getFixedTSLintConfig = getFixedTSLintConfig;
exports.supportES2015 = supportES2015;
exports.get = get;
21 changes: 11 additions & 10 deletions packages/stark-build/config/tslint-disabled-typecheck-rules.json
Original file line number Diff line number Diff line change
@@ -1,43 +1,44 @@
{
"extends": ["TSLINT_CONFIG_PLACEHOLDER"],
"rules": {
"arguments-order": false,
"await-promise": false,
"consecutive-overloads": false,
"deprecation": false,
"match-default-export-name": false,
"no-accessor-field-mismatch": false,
"no-alphabetical-sort": false,
"no-array-delete": false,
"no-boolean-literal-compare": false,
"no-collection-size-mischeck": false,
"no-dead-store": false,
"no-element-overwrite": false,
"no-empty-array": false,
"no-floating-promises": false,
"no-for-in-array": false,
"no-gratuitous-expressions": false,
"no-ignored-initial-value": false,
"no-ignored-return": false,
"no-in-misuse": false,
"no-inferred-empty-object-type": false,
"no-invalid-await": false,
"no-misleading-array-reverse": false,
"no-redundant-boolean": false,
"no-return-type-any": false,
"no-self-assignment": false,
"no-try-promise": false,
"no-undefined-argument": false,
"no-unnecessary-qualifier": false,
"no-unused-array": false,
"no-use-of-empty-return-value": false,
"no-useless-cast": false,
"no-useless-intersection": false,
"no-variable-usage-before-declaration": false,
"no-void-expression": false,
"parameters-max-number": false,
"prefer-immediate-return": false,
"use-type-alias": false,
"no-inferred-empty-object-type": false,
"no-void-expression": false,
"no-boolean-literal-compare": false,
"no-unnecessary-qualifier": false,
"no-floating-promises": false,
"match-default-export-name": false,
"return-undefined": false,
"deprecation": false,
"use-default-type-parameter": false,
"await-promise": false,
"no-for-in-array": false
"use-type-alias": false
}
}
16 changes: 5 additions & 11 deletions packages/stark-build/config/webpack-partial.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const fs = require("fs");
const commonData = require("./webpack.common-data.js"); // common configuration between environments
const buildUtils = require("./build-utils");
const ngCliPackageChunkSort = require("@angular-devkit/build-angular/src/angular-cli-files/utilities/package-chunk-sort");
const os = require("os");

/**
* Webpack Plugins
Expand All @@ -20,18 +19,13 @@ const HtmlElementsWebpackPlugin = require("html-elements-webpack-plugin");
const ContextReplacementPlugin = require("webpack/lib/ContextReplacementPlugin");
const WebpackMonitor = require("webpack-monitor");
const BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
// const WriteFilePlugin = require("write-file-webpack-plugin");
// const StylelintPlugin = require("stylelint-webpack-plugin");
// const InlineManifestWebpackPlugin = require("inline-manifest-webpack-plugin");
// const ScriptExtHtmlWebpackPlugin = require("script-ext-html-webpack-plugin");

const tslintConfig = buildUtils.get(buildUtils.ANGULAR_APP_CONFIG.config, "architect.lint.options.tslintConfig", "tslint.json");
const tslintConfigPath = helpers.root(tslintConfig).replace(/\\/g, "/");
const tslintLoaderFilePath = `${os.tmpdir()}/national-bank-belgium_stark-build_tslint-${new Date().getTime()}.json`;

const tslintDefault = fs.readFileSync(helpers.rootStark("config/tslint-disabled-typecheck-rules.json"), "utf8");
const tslintDefaultEdited = tslintDefault.replace(/TSLINT_CONFIG_PLACEHOLDER/, tslintConfigPath);
fs.writeFileSync(tslintLoaderFilePath, tslintDefaultEdited, "utf8");
const fixedTSLintConfig = buildUtils.getFixedTSLintConfig(
buildUtils.get(buildUtils.ANGULAR_APP_CONFIG.config, "architect.lint.options.tslintConfig", "tslint.json")
);

/**
* Webpack configuration
Expand Down Expand Up @@ -89,9 +83,9 @@ module.exports = metadata => {
{
loader: "tslint-loader",
options: {
typeCheck: false, // FIXME remove this line once the type checking issues are gone (cfr FIXME above)
typeCheck: false, // FIXME enable type checking when it is improved in tslint-loader (https://github.com/wbuchwalter/tslint-loader/pull/114)
tsconfig: buildUtils.ANGULAR_APP_CONFIG.buildOptions.tsconfig || "tsconfig.json",
configFile: tslintLoaderFilePath
configFile: fixedTSLintConfig //FIXME use the configured tslint.json when type checking is enabled
}
}
],
Expand Down

0 comments on commit b38aa7f

Please sign in to comment.