Skip to content

Commit

Permalink
refact: fix eslint warnings (#238)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpza authored Aug 8, 2024
1 parent af66d1c commit f984dc7
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 20 deletions.
18 changes: 8 additions & 10 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,17 @@ export default [
...tseslint.configs.recommended,
{
rules: {
"@typescript-eslint/ban-ts-comment": "warn",
"@typescript-eslint/no-empty-object-type": "warn",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-empty-object-type": ["error", { allowInterfaces: "with-single-extends" }],
"@typescript-eslint/no-namespace": ["error", { allowDeclarations: true }],
"no-empty": ["error", { allowEmptyCatch: true }],
"prefer-const": ["error", { destructuring: "all" }],
},
},
{
rules: {
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-require-imports": "off",
"@typescript-eslint/no-unsafe-function-type": "warn",
"@typescript-eslint/no-unused-vars": "warn",
"no-case-declarations": "warn",
"no-empty": "warn",
"no-useless-escape": "warn",
"prefer-const": "off",
"prefer-rest-params": "warn",
"prefer-spread": "warn",
},
},
];
2 changes: 1 addition & 1 deletion src/harmony/versions/three-eight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export function handler(context: TsTransformPathsContext, prop: string | symbol)
dsNode.modifiers,
dsExportClause,
dsModuleSpecifier,
// @ts-ignore - This was added in later versions of 3.x
// @ts-expect-error - This was added in later versions of 3.x
dsNode.isTypeOnly,
);
};
Expand Down
2 changes: 1 addition & 1 deletion src/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export function register(): TSNode.RegisterOptions | undefined {
const registerOptions: TSNode.RegisterOptions = Object.assign({}, tsNodeInstance.options);
if (registerOptions.transformers) {
if (typeof registerOptions.transformers === "function") {
let oldTransformersFactory = registerOptions.transformers;
const oldTransformersFactory = registerOptions.transformers;
registerOptions.transformers = (program) => {
const transformers = getTransformers(program, beforeConfig, afterDeclarationsConfig);
const baseTransformers = oldTransformersFactory(program);
Expand Down
4 changes: 2 additions & 2 deletions src/transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import { TransformerExtras } from "ts-patch";
/* ****************************************************************************************************************** */

function getTsProperties(args: Parameters<typeof transformer>) {
let tsInstance: typeof ts;
let fileNames: readonly string[] | undefined;
let compilerOptions: CompilerOptions;
let runMode: RunMode;
let tsNodeState: TsNodeState | undefined;

const { 0: program, 2: extras, 3: manualTransformOptions } = args;

tsInstance = extras?.ts ?? ts;
const tsInstance = extras?.ts ?? ts;

if (program) compilerOptions = program.getCompilerOptions();
const tsNodeProps = getTsNodeRegistrationProperties(tsInstance);

Expand Down
2 changes: 1 addition & 1 deletion src/utils/resolve-module-name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ enum IndexType {
/* ****************************************************************************************************************** */

function getPathDetail(moduleName: string, resolvedModule: ResolvedModuleFull) {
let resolvedFileName = resolvedModule.originalPath ?? resolvedModule.resolvedFileName;
const resolvedFileName = resolvedModule.originalPath ?? resolvedModule.resolvedFileName;
const implicitPackageIndex = resolvedModule.packageId?.subModuleName;

const resolvedDir = implicitPackageIndex
Expand Down
5 changes: 3 additions & 2 deletions test/tests/transformer/specific.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe(`Specific Tests`, () => {

beforeAll(() => {
switch (mode) {
case "program":
case "program": {
const program = createTsProgram({
tsInstance,
tsConfigFile,
Expand All @@ -81,6 +81,7 @@ describe(`Specific Tests`, () => {
});
rootDirsEmit = getEmitResultFromProgram(rootDirsProgram);
break;
}
case "manual": {
skipDts = true;
const pcl = tsInstance.getParsedCommandLineOfConfigFile(
Expand Down Expand Up @@ -159,7 +160,7 @@ describe(`Specific Tests`, () => {
describe(`Tags`, () => {
test(`(@no-transform-path) Doesn't transform path`, () => {
for (let i = 1; i <= 4; i++)
expect(tagFile).transformedMatches(`import * as skipTransform${i} from "#root\/index`);
expect(tagFile).transformedMatches(`import * as skipTransform${i} from "#root/index`);
});

test(`(@transform-path) Transforms path with explicit value`, () => {
Expand Down
9 changes: 6 additions & 3 deletions test/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ function createWriteFile(outputFiles: EmittedFiles) {
};
}

function createReadFile(outputFiles: EmittedFiles, originalReadFile: Function) {
function createReadFile(
outputFiles: EmittedFiles,
originalReadFile: (path: string, encoding?: string) => string | undefined,
) {
return (fileName: string) => {
let { 1: rootName, 2: ext } = fileName.match(/(.+)\.((d.ts)|(js))$/) ?? [];
if (ext) {
Expand Down Expand Up @@ -111,10 +114,10 @@ export function createTsProgram(

/* Patch host to feed mock files */
const originalGetSourceFile: any = host.getSourceFile;
host.getSourceFile = function (fileName: string, scriptTarget: ts.ScriptTarget) {
host.getSourceFile = function (fileName: string, scriptTarget: ts.ScriptTarget, ...rest) {
if (Object.keys(files).includes(fileName))
return tsInstance.createSourceFile(fileName, files[fileName], scriptTarget);
else originalGetSourceFile.apply(undefined, arguments);
else originalGetSourceFile(fileName, scriptTarget, ...rest);
};
}

Expand Down

0 comments on commit f984dc7

Please sign in to comment.