Skip to content

Commit

Permalink
test: eslint in loaders
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Aug 26, 2024
1 parent beb4571 commit 400dd2e
Show file tree
Hide file tree
Showing 32 changed files with 208 additions and 224 deletions.
9 changes: 4 additions & 5 deletions demo/esm/test/loaders/all.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@

import * as coffee from './coffee.js'
import * as ts from 'ts-node/esm'
import * as coffee from "./coffee.js";
import * as ts from "ts-node/esm";

const coffeeRegex = /\.coffee$|\.litcoffee$|\.coffee\.md$/;
const tsRegex = /\.ts$/;

export function load(url, context, next) {
if (coffeeRegex.test(url)) {
return coffee.load.apply(this, arguments)
return coffee.load.apply(this, arguments);
}
if (tsRegex.test(url)) {
return ts.load.apply(this, arguments)
return ts.load.apply(this, arguments);
}
return next(url, context, next);
}
6 changes: 3 additions & 3 deletions demo/esm/test/loaders/coffee.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import CoffeeScript from 'coffeescript';
import CoffeeScript from "coffeescript";

// See https://github.com/nodejs/node/issues/36396
const extensionsRegex = /\.coffee$|\.litcoffee$|\.coffee\.md$/;

export async function load(url, context, next) {
if (extensionsRegex.test(url)) {
const format = 'module';
const format = "module";
const { source: rawSource } = await next(url, { format });
const source = CoffeeScript.compile(rawSource.toString(), {
bare: true,
Expand All @@ -14,7 +14,7 @@ export async function load(url, context, next) {
header: false,
sourceMap: false,
});
return {format, source};
return { format, source };
}
return next(url, context);
}
23 changes: 11 additions & 12 deletions demo/esm/test/loaders/legacy/all.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@

import * as coffee from './coffee.js'
import * as ts from 'ts-node/esm'
import * as coffee from "./coffee.js";
import * as ts from "ts-node/esm";

const coffeeRegex = /\.coffee$|\.litcoffee$|\.coffee\.md$/;
const tsRegex = /\.ts$/;

export function resolve(specifier, context, defaultResolve) {
export function resolve(specifier) {
if (coffeeRegex.test(specifier)) {
return coffee.resolve.apply(this, arguments)
return coffee.resolve.apply(this, arguments);
}
if (tsRegex.test(specifier)) {
return ts.resolve.apply(this, arguments)
return ts.resolve.apply(this, arguments);
}
return ts.resolve.apply(this, arguments);
}

export function getFormat(url, context, defaultGetFormat) {
export function getFormat(url) {
if (coffeeRegex.test(url)) {
return coffee.getFormat.apply(this, arguments)
return coffee.getFormat.apply(this, arguments);
}
if (tsRegex.test(url)) {
return ts.getFormat.apply(this, arguments)
return ts.getFormat.apply(this, arguments);
}
return ts.getFormat.apply(this, arguments);
}

export function transformSource(source, context, defaultTransformSource) {
export function transformSource(source, context) {
const { url } = context;
if (coffeeRegex.test(url)) {
return coffee.transformSource.apply(this, arguments)
return coffee.transformSource.apply(this, arguments);
}
if (tsRegex.test(url)) {
return ts.transformSource.apply(this, arguments)
return ts.transformSource.apply(this, arguments);
}
return ts.transformSource.apply(this, arguments);
}
16 changes: 8 additions & 8 deletions demo/esm/test/loaders/legacy/coffee.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// coffeescript-loader.mjs
import { URL, pathToFileURL } from 'url';
import CoffeeScript from 'coffeescript';
import { cwd } from 'process';
import { URL, pathToFileURL } from "url";
import CoffeeScript from "coffeescript";
import { cwd } from "process";

const baseURL = pathToFileURL(`${cwd()}/`).href;

Expand All @@ -15,7 +15,7 @@ export function resolve(specifier, context, defaultResolve) {
if (extensionsRegex.test(specifier)) {
return {
url: new URL(specifier, parentURL).href,
stop: true
stop: true,
};
}
// Let Node.js handle all other specifiers.
Expand All @@ -28,20 +28,20 @@ export function getFormat(url, context, defaultGetFormat) {
// purposes of this loader, all CoffeeScript URLs are ES modules.
if (extensionsRegex.test(url)) {
return {
format: 'module',
stop: true
format: "module",
stop: true,
};
}
// Let Node.js handle all other URLs.
return defaultGetFormat(url, context, defaultGetFormat);
}

export function transformSource(source, context, defaultTransformSource) {
const { url, format } = context;
const { url } = context;

if (extensionsRegex.test(url)) {
return {
source: CoffeeScript.compile(String(source), { bare: true })
source: CoffeeScript.compile(String(source), { bare: true }),
};
}

Expand Down
9 changes: 4 additions & 5 deletions demo/issues-esm/test/loaders/all.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@

import * as coffee from './coffee.js'
import * as ts from 'ts-node/esm'
import * as coffee from "./coffee.js";
import * as ts from "ts-node/esm";

const coffeeRegex = /\.coffee$|\.litcoffee$|\.coffee\.md$/;
const tsRegex = /\.ts$/;

export function load(url, context, next) {
if (coffeeRegex.test(url)) {
return coffee.load.apply(this, arguments)
return coffee.load.apply(this, arguments);
}
if (tsRegex.test(url)) {
return ts.load.apply(this, arguments)
return ts.load.apply(this, arguments);
}
return next(url, context, next);
}
6 changes: 3 additions & 3 deletions demo/issues-esm/test/loaders/coffee.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import CoffeeScript from 'coffeescript';
import CoffeeScript from "coffeescript";

// See https://github.com/nodejs/node/issues/36396
const extensionsRegex = /\.coffee$|\.litcoffee$|\.coffee\.md$/;

export async function load(url, context, next) {
if (extensionsRegex.test(url)) {
const format = 'module';
const format = "module";
const { source: rawSource } = await next(url, { format });
const source = CoffeeScript.compile(rawSource.toString(), {
bare: true,
Expand All @@ -14,7 +14,7 @@ export async function load(url, context, next) {
header: false,
sourceMap: false,
});
return {format, source};
return { format, source };
}
return next(url, context);
}
23 changes: 11 additions & 12 deletions demo/issues-esm/test/loaders/legacy/all.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@

import * as coffee from './coffee.js'
import * as ts from 'ts-node/esm'
import * as coffee from "./coffee.js";
import * as ts from "ts-node/esm";

const coffeeRegex = /\.coffee$|\.litcoffee$|\.coffee\.md$/;
const tsRegex = /\.ts$/;

export function resolve(specifier, context, defaultResolve) {
export function resolve(specifier) {
if (coffeeRegex.test(specifier)) {
return coffee.resolve.apply(this, arguments)
return coffee.resolve.apply(this, arguments);
}
if (tsRegex.test(specifier)) {
return ts.resolve.apply(this, arguments)
return ts.resolve.apply(this, arguments);
}
return ts.resolve.apply(this, arguments);
}

export function getFormat(url, context, defaultGetFormat) {
export function getFormat(url) {
if (coffeeRegex.test(url)) {
return coffee.getFormat.apply(this, arguments)
return coffee.getFormat.apply(this, arguments);
}
if (tsRegex.test(url)) {
return ts.getFormat.apply(this, arguments)
return ts.getFormat.apply(this, arguments);
}
return ts.getFormat.apply(this, arguments);
}

export function transformSource(source, context, defaultTransformSource) {
export function transformSource(source, context) {
const { url } = context;
if (coffeeRegex.test(url)) {
return coffee.transformSource.apply(this, arguments)
return coffee.transformSource.apply(this, arguments);
}
if (tsRegex.test(url)) {
return ts.transformSource.apply(this, arguments)
return ts.transformSource.apply(this, arguments);
}
return ts.transformSource.apply(this, arguments);
}
16 changes: 8 additions & 8 deletions demo/issues-esm/test/loaders/legacy/coffee.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// coffeescript-loader.mjs
import { URL, pathToFileURL } from 'url';
import CoffeeScript from 'coffeescript';
import { cwd } from 'process';
import { URL, pathToFileURL } from "url";
import CoffeeScript from "coffeescript";
import { cwd } from "process";

const baseURL = pathToFileURL(`${cwd()}/`).href;

Expand All @@ -15,7 +15,7 @@ export function resolve(specifier, context, defaultResolve) {
if (extensionsRegex.test(specifier)) {
return {
url: new URL(specifier, parentURL).href,
stop: true
stop: true,
};
}
// Let Node.js handle all other specifiers.
Expand All @@ -28,20 +28,20 @@ export function getFormat(url, context, defaultGetFormat) {
// purposes of this loader, all CoffeeScript URLs are ES modules.
if (extensionsRegex.test(url)) {
return {
format: 'module',
stop: true
format: "module",
stop: true,
};
}
// Let Node.js handle all other URLs.
return defaultGetFormat(url, context, defaultGetFormat);
}

export function transformSource(source, context, defaultTransformSource) {
const { url, format } = context;
const { url } = context;

if (extensionsRegex.test(url)) {
return {
source: CoffeeScript.compile(String(source), { bare: true })
source: CoffeeScript.compile(String(source), { bare: true }),
};
}

Expand Down
9 changes: 4 additions & 5 deletions demo/ts-esm-node16/test/loaders/all.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@

import * as coffee from './coffee.js'
import * as ts from 'ts-node/esm'
import * as coffee from "./coffee.js";
import * as ts from "ts-node/esm";

const coffeeRegex = /\.coffee$|\.litcoffee$|\.coffee\.md$/;
const tsRegex = /\.ts$/;

export function load(url, context, next) {
if (coffeeRegex.test(url)) {
return coffee.load.apply(this, arguments)
return coffee.load.apply(this, arguments);
}
if (tsRegex.test(url)) {
return ts.load.apply(this, arguments)
return ts.load.apply(this, arguments);
}
return next(url, context, next);
}
6 changes: 3 additions & 3 deletions demo/ts-esm-node16/test/loaders/coffee.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import CoffeeScript from 'coffeescript';
import CoffeeScript from "coffeescript";

// See https://github.com/nodejs/node/issues/36396
const extensionsRegex = /\.coffee$|\.litcoffee$|\.coffee\.md$/;

export async function load(url, context, next) {
if (extensionsRegex.test(url)) {
const format = 'module';
const format = "module";
const { source: rawSource } = await next(url, { format });
const source = CoffeeScript.compile(rawSource.toString(), {
bare: true,
Expand All @@ -14,7 +14,7 @@ export async function load(url, context, next) {
header: false,
sourceMap: false,
});
return {format, source};
return { format, source };
}
return next(url, context);
}
23 changes: 11 additions & 12 deletions demo/ts-esm-node16/test/loaders/legacy/all.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@

import * as coffee from './coffee.js'
import * as ts from 'ts-node/esm'
import * as coffee from "./coffee.js";
import * as ts from "ts-node/esm";

const coffeeRegex = /\.coffee$|\.litcoffee$|\.coffee\.md$/;
const tsRegex = /\.ts$/;

export function resolve(specifier, context, defaultResolve) {
export function resolve(specifier) {
if (coffeeRegex.test(specifier)) {
return coffee.resolve.apply(this, arguments)
return coffee.resolve.apply(this, arguments);
}
if (tsRegex.test(specifier)) {
return ts.resolve.apply(this, arguments)
return ts.resolve.apply(this, arguments);
}
return ts.resolve.apply(this, arguments);
}

export function getFormat(url, context, defaultGetFormat) {
export function getFormat(url) {
if (coffeeRegex.test(url)) {
return coffee.getFormat.apply(this, arguments)
return coffee.getFormat.apply(this, arguments);
}
if (tsRegex.test(url)) {
return ts.getFormat.apply(this, arguments)
return ts.getFormat.apply(this, arguments);
}
return ts.getFormat.apply(this, arguments);
}

export function transformSource(source, context, defaultTransformSource) {
export function transformSource(source, context) {
const { url } = context;
if (coffeeRegex.test(url)) {
return coffee.transformSource.apply(this, arguments)
return coffee.transformSource.apply(this, arguments);
}
if (tsRegex.test(url)) {
return ts.transformSource.apply(this, arguments)
return ts.transformSource.apply(this, arguments);
}
return ts.transformSource.apply(this, arguments);
}
Loading

0 comments on commit 400dd2e

Please sign in to comment.