Skip to content

Commit

Permalink
add support to tslint.json linterOptions.exclude (#377)
Browse files Browse the repository at this point in the history
* add support to exclude linting

* improved readability of tslint exclude transform
  • Loading branch information
Paul authored Feb 6, 2020
1 parent 339ec2b commit 5e977d8
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/base.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import * as webpack from 'webpack';
import * as cssnano from 'cssnano';
import * as minimatch from 'minimatch';
import * as ManifestPlugin from 'webpack-manifest-plugin';
import * as globby from 'globby';

const postcssPresetEnv = require('postcss-preset-env');
const postcssImport = require('postcss-import');
Expand Down Expand Up @@ -45,6 +46,13 @@ export const packageName = packageJson.name || '';
const tsLintPath = path.join(basePath, 'tslint.json');
const tsLint = existsSync(tsLintPath) ? require(tsLintPath) : false;

function getTsLintExclusions() {
if (tsLint && tsLint.linterOptions && tsLint.linterOptions.exclude) {
return globby.sync(tsLint.linterOptions.exclude).map((file) => path.resolve(file));
}
return [];
}

function getLibraryName(name: string) {
return name
.replace(/[^a-z0-9_]/g, ' ')
Expand Down Expand Up @@ -560,7 +568,8 @@ export default function webpackConfigFactory(args: any): webpack.Configuration {
test: /\.(ts|tsx)$/,
enforce: 'pre',
loader: 'tslint-loader',
options: { configuration: tsLint, emitErrors: true, failOnHint: true }
options: { configuration: tsLint, emitErrors: true, failOnHint: true },
exclude: getTsLintExclusions()
},
{
test: /@dojo(\/|\\).*\.(js|mjs)$/,
Expand Down
1 change: 1 addition & 0 deletions test-app/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { registerRouterInjector } from '@dojo/framework/routing/RouterInjector';
import App from './App';
import * as css from './app.m.css';
import './Bar';
import './tslintTest';
import LazyApp from './LazyApp';
import routes from './routes';
import test from './test.block';
Expand Down
2 changes: 2 additions & 0 deletions test-app/src/tslintTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// This would fail linting without `exclude` support from @dojo/cli-build-app
export var thisWouldFailLinting: any;
40 changes: 40 additions & 0 deletions test-app/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"rules": {
"align": false,
"ban": [],
"class-name": true,
"comment-format": [ true, "check-space" ],
"curly": true,
"forin": false,
"interface-name": [ true, "never-prefix" ],
"jsdoc-format": true,
"label-position": true,
"member-access": false,
"member-ordering": false,
"no-any": false,
"no-arg": true,
"no-bitwise": false,
"no-console": false,
"no-construct": false,
"no-debugger": true,
"no-duplicate-variable": true,
"no-empty": false,
"no-eval": true,
"no-inferrable-types": [ true, "ignore-params" ],
"no-shadowed-variable": false,
"no-string-literal": false,
"no-switch-case-fall-through": false,
"no-unused-expression": false,
"no-use-before-declare": false,
"no-var-keyword": true,
"no-var-requires": false,
"object-literal-sort-keys": false,
"radix": true,
"triple-equals": [ true, "allow-null-check" ],
"typedef": false,
"variable-name": [ true, "check-format", "allow-leading-underscore", "ban-keywords", "allow-pascal-case" ]
},
"linterOptions": {
"exclude": [ "**/tslint*.ts" ]
}
}

0 comments on commit 5e977d8

Please sign in to comment.