Skip to content

Commit

Permalink
chore: change to using rome linter instead of eslint
Browse files Browse the repository at this point in the history
The `eslint` linter has become large and unwieldly with frequent updates
and too many transitive dependencies. This PR changes the linter to
Rome (https://rome.tools/). Rome can handle both formatting and linting,
is very fast, and requires minimal configuration.

I've added a single configuration option in `rome.json` which specifies
using single quotes, which I'm not married to, but it seems pointless to
change the quote style everywhere. I'm happy to add additional linting
or formatting rules to reduce the number of changes with this PR, but
honestly, I'm happy to go with what's already the default if that
doesn't cause this PR to be too disruptive.

Signed-off-by: Lance Ball <lball@redhat.com>
  • Loading branch information
lance committed Jul 20, 2023
1 parent c8440f5 commit f3f0dbb
Show file tree
Hide file tree
Showing 45 changed files with 2,135 additions and 3,535 deletions.
33 changes: 0 additions & 33 deletions .eslintrc

This file was deleted.

81 changes: 49 additions & 32 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,60 @@ const { Command } = require('commander');
const program = new Command();

program
.version(pkg.version)
.option('--log-level <log-level>', 'change the log level of the function', defaults.LOG_LEVEL)
.option('--port <port>', 'change the port the runtime listens on', defaults.PORT)
.option('--include-raw', 'include the raw body in the request context', defaults.INCLUDE_RAW)
.arguments('<file>')
.action(runServer);
.version(pkg.version)
.option(
'--log-level <log-level>',
'change the log level of the function',
defaults.LOG_LEVEL,
)
.option(
'--port <port>',
'change the port the runtime listens on',
defaults.PORT,
)
.option(
'--include-raw',
'include the raw body in the request context',
defaults.INCLUDE_RAW,
)
.arguments('<file>')
.action(runServer);

program.parse(process.argv);

async function runServer(file) {
const programOpts = program.opts();

try {
let options = {
logLevel: process.env.FUNC_LOG_LEVEL || programOpts['logLevel'] || defaults.LOG_LEVEL,
port: process.env.FUNC_PORT || programOpts.port || defaults.PORT,
includeRaw: process.env.FUNC_INCLUDE_RAW ? true : programOpts.includeRaw || defaults.INCLUDE_RAW,
};

const filePath = extractFullPath(file);
const code = await loadFunction(filePath);

// The module will extract `handle` and other lifecycle functions
// from `code` if it is an object. If it's just a function, it will
// be used directly.
if (typeof code === 'function' || typeof code === 'object') {
return start(code, options);
} else {
console.error(code);
throw TypeError(`Cannot find Invokable function 'handle' in ${code}`);
}
} catch (error) {
console.error(`⛔ ${error}`);
}
const programOpts = program.opts();

try {
const options = {
logLevel:
process.env.FUNC_LOG_LEVEL ||
programOpts['logLevel'] ||
defaults.LOG_LEVEL,
port: process.env.FUNC_PORT || programOpts.port || defaults.PORT,
includeRaw: process.env.FUNC_INCLUDE_RAW
? true
: programOpts.includeRaw || defaults.INCLUDE_RAW,
};

const filePath = extractFullPath(file);
const code = await loadFunction(filePath);

// The module will extract `handle` and other lifecycle functions
// from `code` if it is an object. If it's just a function, it will
// be used directly.
if (typeof code === 'function' || typeof code === 'object') {
return start(code, options);
} else {
console.error(code);
throw TypeError(`Cannot find Invokable function 'handle' in ${code}`);
}
} catch (error) {
console.error(`⛔ ${error}`);
}
}

function extractFullPath(file) {
if (path.isAbsolute(file)) return file;
return path.join(process.cwd(), file);
if (path.isAbsolute(file)) return file;
return path.join(process.cwd(), file);
}
18 changes: 9 additions & 9 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ import { LogLevel } from 'fastify';
export type Invokable = CloudEventFunction | HTTPFunction;

export interface Config {
logLevel: LogLevel;
port: number;
includeRaw: boolean;
logLevel: LogLevel;
port: number;
includeRaw: boolean;
}

// start starts the server for the given function.
export declare const start: {
// eslint-disable-next-line no-unused-vars
(func: Invokable | Function, options?: InvokerOptions): Promise<Server>
// eslint-disable-next-line no-unused-vars
(func: Invokable | Function, options?: InvokerOptions): Promise<Server>;
};

export declare const defaults: {
LOG_LEVEL: LogLevel,
PORT: number,
INCLUDE_RAW: boolean,
}
LOG_LEVEL: LogLevel;
PORT: number;
INCLUDE_RAW: boolean;
};

// re-export
export * from './lib/types';
Loading

0 comments on commit f3f0dbb

Please sign in to comment.