Skip to content

Commit

Permalink
migrate from tslint to eslint (#1120)
Browse files Browse the repository at this point in the history
* migrate from tslint to eslint

* unignore .eslintrc.js
  • Loading branch information
johnnyreilly committed May 26, 2020
1 parent e39b9f4 commit 466d067
Show file tree
Hide file tree
Showing 227 changed files with 859 additions and 43,945 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
@@ -0,0 +1,3 @@
/.test/**
/dist/**
/test/**
37 changes: 37 additions & 0 deletions .eslintrc.js
@@ -0,0 +1,37 @@
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
extends: ['plugin:node/recommended', 'plugin:prettier/recommended'],
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
},
settings: {
node: {
tryExtensions: ['.js', '.json', '.ts', '.d.ts'],
},
},
rules: {
// 'no-process-exit': 'off', // to investigate if we should throw an error instead of process.exit()
// 'node/no-unsupported-features/es-builtins': 'off',
},
overrides: [
{
files: ['*.ts'],
extends: [
'plugin:@typescript-eslint/recommended', // Uses the recommended rules from the @typescript-eslint/eslint-plugin
'prettier/@typescript-eslint', // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier
'plugin:prettier/recommended', // Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
],
rules: {
'node/no-unsupported-features/es-syntax': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unused-vars': 'off',
// '@typescript-eslint/explicit-function-return-type': 'off',
// '@typescript-eslint/no-namespace': 'off' // maybe we should consider enabling it in the future
},
},
],
};
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -16,4 +16,5 @@ npm-debug.log
!build.js
/**/debug.log
.pnp
.pnp.js
.pnp.js
!.eslintrc.js
1 change: 1 addition & 0 deletions .prettierignore
@@ -0,0 +1 @@
/test/**
8 changes: 8 additions & 0 deletions .prettierrc
@@ -0,0 +1,8 @@
{
"arrowParens": "avoid",
"singleQuote": true,
"semi": true,
"tabWidth": 2,
"useTabs": false,
"printWidth": 80
}
13 changes: 9 additions & 4 deletions package.json
Expand Up @@ -6,7 +6,7 @@
"types": "dist",
"scripts": {
"build": "tsc --version && tsc --project \"./src\"",
"lint": "tslint --project \"./src\"",
"lint": "eslint -c .eslintrc.js --ext .ts ./src",
"comparison-tests": "git clean -xfd test/comparison-tests && npm link ./test/comparison-tests/testLib && node test/comparison-tests/run-tests.js",
"comparison-tests-generate": "git clean -xfd test/comparison-tests && node test/comparison-tests/stub-new-version.js",
"execution-tests": "git clean -xfd test/execution-tests && node test/execution-tests/run-tests.js",
Expand All @@ -24,6 +24,7 @@
"lint-staged": {
"src/**/*.{ts,md}": [
"prettier --write",
"yarn lint",
"git add"
]
},
Expand Down Expand Up @@ -64,6 +65,8 @@
"@types/node": "*",
"@types/semver": "^6.0.0",
"@types/webpack": "^4.4.30",
"@typescript-eslint/eslint-plugin": "^3.0.0",
"@typescript-eslint/parser": "^3.0.0",
"babel": "^6.0.0",
"babel-core": "^6.0.0",
"babel-loader": "^7.0.0",
Expand All @@ -72,6 +75,10 @@
"babel-preset-es2016": "^6.16.0",
"babel-preset-react": "^6.0.0",
"escape-string-regexp": "^2.0.0",
"eslint": "^7.1.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.1.3",
"fs-extra": "^7.0.0",
"glob": "^7.1.1",
"html-webpack-plugin": "^3.2.0",
Expand All @@ -87,10 +94,8 @@
"markdown-toc": "^1.2.0",
"mkdirp": "^0.5.1",
"mocha": "^6.0.0",
"prettier": "^1.11.1",
"prettier": "^2.0.5",
"rimraf": "^2.6.2",
"tslint": "^5.11.0",
"tslint-config-prettier": "^1.15.0",
"typescript": "^3.6.2",
"webpack": "^4.5.0",
"webpack-cli": "^3.1.1"
Expand Down
10 changes: 0 additions & 10 deletions src/.prettierrc

This file was deleted.

12 changes: 6 additions & 6 deletions src/after-compile.ts
Expand Up @@ -6,20 +6,20 @@ import * as constants from './constants';
import {
getEmitFromWatchHost,
getEmitOutput,
isReferencedFile
isReferencedFile,
} from './instances';
import {
TSFile,
TSFiles,
TSInstance,
WebpackError,
WebpackModule
WebpackModule,
} from './interfaces';
import {
collectAllDependants,
ensureProgram,
formatErrors,
isUsingProjectReferences
isUsingProjectReferences,
} from './utils';

export function makeAfterCompile(
Expand Down Expand Up @@ -190,7 +190,7 @@ function provideErrorsToWebpack(
files,
loaderOptions,
compilerOptions,
otherFiles
otherFiles,
} = instance;

const filePathRegex =
Expand Down Expand Up @@ -284,7 +284,7 @@ function provideSolutionErrorsToWebpack(
const {
compiler,
loaderOptions,
solutionBuilderHost: { diagnostics }
solutionBuilderHost: { diagnostics },
} = instance;

for (const [filePath, perFileDiagnostics] of diagnostics.perFile) {
Expand Down Expand Up @@ -380,7 +380,7 @@ function outputFileToAsset(
);
compilation.assets[assetPath] = {
source: () => outputFile.text,
size: () => outputFile.text.length
size: () => outputFile.text.length,
};
}

Expand Down
14 changes: 6 additions & 8 deletions src/compilerSetup.ts
Expand Up @@ -16,9 +16,7 @@ export function getCompiler(loaderOptions: LoaderOptions, log: logger.Logger) {
errorMessage =
loaderOptions.compiler === 'typescript'
? 'Could not load TypeScript. Try installing with `yarn add typescript` or `npm install typescript`. If TypeScript is installed globally, try using `yarn link typescript` or `npm link typescript`.'
: `Could not load TypeScript compiler with NPM package name \`${
loaderOptions.compiler
}\`. Are you sure it is correctly installed?`;
: `Could not load TypeScript compiler with NPM package name \`${loaderOptions.compiler}\`. Are you sure it is correctly installed?`;
}

if (errorMessage === undefined) {
Expand Down Expand Up @@ -49,7 +47,7 @@ export function getCompiler(loaderOptions: LoaderOptions, log: logger.Logger) {
compiler,
compilerCompatible,
compilerDetailsLogMessage,
errorMessage
errorMessage,
};
}

Expand All @@ -58,14 +56,14 @@ export function getCompilerOptions(
) {
const compilerOptions = Object.assign({}, configParseResult.options, {
skipLibCheck: true,
suppressOutputPathCheck: true // This is why: https://github.com/Microsoft/TypeScript/issues/7363
suppressOutputPathCheck: true, // This is why: https://github.com/Microsoft/TypeScript/issues/7363
} as typescript.CompilerOptions);

// if `module` is not specified and not using ES6+ target, default to CJS module output
if (
compilerOptions.module === undefined &&
(compilerOptions.target !== undefined &&
compilerOptions.target < typescript.ScriptTarget.ES2015)
compilerOptions.target !== undefined &&
compilerOptions.target < typescript.ScriptTarget.ES2015
) {
compilerOptions.module = typescript.ModuleKind.CommonJS;
}
Expand All @@ -74,7 +72,7 @@ export function getCompilerOptions(
Object.defineProperty(compilerOptions, 'configFile', {
enumerable: false,
writable: false,
value: configParseResult.options.configFile
value: configParseResult.options.configFile,
});
}

Expand Down
11 changes: 6 additions & 5 deletions src/config.ts
Expand Up @@ -58,8 +58,8 @@ export function getConfigFile(
configFile = {
config: {
compilerOptions: {},
files: []
}
files: [],
},
};
}

Expand All @@ -74,7 +74,7 @@ export function getConfigFile(
return {
configFilePath,
configFile,
configFileError
configFileError,
};
}

Expand Down Expand Up @@ -144,7 +144,7 @@ export function getConfigParseResult(
if (semver.gte(compiler.version, '3.5.0')) {
// set internal options.configFilePath flag on options to denote that we read this from a file
configParseResult.options = Object.assign({}, configParseResult.options, {
configFilePath
configFilePath,
});
}

Expand All @@ -164,7 +164,8 @@ export function getParsedCommandLine(
loaderOptions.compilerOptions,
{
...compiler.sys,
onUnRecoverableConfigFileDiagnostic: () => {} // tslint:disable-line no-empty
// eslint-disable-next-line @typescript-eslint/no-empty-function
onUnRecoverableConfigFileDiagnostic: () => {},
},
extendedConfigCache
);
Expand Down
34 changes: 15 additions & 19 deletions src/index.ts
Expand Up @@ -12,22 +12,22 @@ import {
getTypeScriptInstance,
initializeInstance,
isReferencedFile,
reportTranspileErrors
reportTranspileErrors,
} from './instances';
import {
LoaderOptions,
LoaderOptionsCache,
LogLevel,
TSFile,
TSInstance
TSInstance,
} from './interfaces';
import {
appendSuffixesIfMatch,
arrify,
formatErrors,
getAndCacheOutputJSFileName,
getAndCacheProjectReference,
validateSourceMapOncePerProject
validateSourceMapOncePerProject,
} from './utils';

const webpackInstances: webpack.Compiler[] = [];
Expand All @@ -37,7 +37,6 @@ const loaderOptionsCache: LoaderOptionsCache = {};
* The entry point for ts-loader
*/
function loader(this: webpack.loader.LoaderContext, contents: string) {
// tslint:disable-next-line:no-unused-expression strict-boolean-expressions
this.cacheable && this.cacheable();
const callback = this.async() as webpack.loader.loaderCallback;
const options = getLoaderOptions(this);
Expand Down Expand Up @@ -68,7 +67,7 @@ function successLoader(
? appendSuffixesIfMatch(
{
'.ts': instance.loaderOptions.appendTsSuffixTo,
'.tsx': instance.loaderOptions.appendTsxSuffixTo
'.tsx': instance.loaderOptions.appendTsxSuffixTo,
},
rawFilePath
)
Expand All @@ -87,7 +86,7 @@ function successLoader(
loaderContext.rootContext,
referencedProject.sourceFile.fileName
),
path.relative(loaderContext.rootContext, filePath)
path.relative(loaderContext.rootContext, filePath),
];
if (referencedProject.commandLine.options.outFile !== undefined) {
throw new Error(
Expand Down Expand Up @@ -303,7 +302,7 @@ const validLoaderOptions: ValidLoaderOptions[] = [
'experimentalFileCaching',
'projectReferences',
'resolveModuleName',
'resolveTypeReferenceDirective'
'resolveTypeReferenceDirective',
];

/**
Expand All @@ -313,7 +312,6 @@ const validLoaderOptions: ValidLoaderOptions[] = [
*/
function validateLoaderOptions(loaderOptions: LoaderOptions) {
const loaderOptionKeys = Object.keys(loaderOptions);
// tslint:disable-next-line:prefer-for-of
for (let i = 0; i < loaderOptionKeys.length; i++) {
const option = loaderOptionKeys[i];
const isUnexpectedOption =
Expand All @@ -332,9 +330,7 @@ ${validLoaderOptions.join(' / ')}
!path.isAbsolute(loaderOptions.context)
) {
throw new Error(
`Option 'context' has to be an absolute path. Given '${
loaderOptions.context
}'.`
`Option 'context' has to be an absolute path. Given '${loaderOptions.context}'.`
);
}
}
Expand All @@ -361,7 +357,7 @@ function makeLoaderOptions(instanceName: string, loaderOptions: LoaderOptions) {
// When the watch API usage stabilises look to remove this option and make watch usage the default behaviour when available
experimentalWatchApi: false,
allowTsInNodeModules: false,
experimentalFileCaching: true
experimentalFileCaching: true,
} as Partial<LoaderOptions>,
loaderOptions
);
Expand Down Expand Up @@ -606,7 +602,7 @@ function addDependenciesFromSolutionBuilder(
// Referenced file find the config for it
for (const [
configFile,
configInfo
configInfo,
] of instance.solutionBuilderHost.configFileInfo.entries()) {
if (
!configInfo.config ||
Expand Down Expand Up @@ -705,12 +701,12 @@ function getTranspilationEmit(
const {
outputText,
sourceMapText,
diagnostics
diagnostics,
} = instance.compiler.transpileModule(contents, {
compilerOptions: { ...instance.compilerOptions, rootDir: undefined },
transformers: instance.transformers,
reportDiagnostics: true,
fileName
fileName,
});

addDependenciesFromSolutionBuilder(instance, fileName, file =>
Expand Down Expand Up @@ -750,8 +746,8 @@ function makeSourceMap(
sourceMap: Object.assign(JSON.parse(sourceMapText), {
sources: [loaderUtils.getRemainingRequest(loaderContext)],
file: filePath,
sourcesContent: [contents]
})
sourcesContent: [contents],
}),
};
}

Expand All @@ -760,8 +756,8 @@ export = loader;
/**
* expose public types via declaration merging
*/
// tslint:disable-next-line:no-namespace
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace loader {
// tslint:disable-next-line:no-empty-interface
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface Options extends LoaderOptions {}
}

0 comments on commit 466d067

Please sign in to comment.