Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[INTERNAL] enable noUnusedParameters and noImplicitReturns rules. fix problems #1256

Merged
merged 5 commits into from
Oct 22, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/cli/domain/get-mocked-plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ const isMockValid = (
};

const defaultRegister = (
options: unknown,
dependencies: unknown,
_options: unknown,
_dependencies: unknown,
next: () => void
) => {
next();
Expand Down
2 changes: 1 addition & 1 deletion src/cli/domain/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default function mock() {
params: { targetType: string; targetValue: string; targetName: string },
callback: (err: Error) => void
): void {
fs.readJson(settings.configFile.src, (err, localConfig) => {
fs.readJson(settings.configFile.src, (_err, localConfig) => {
localConfig = localConfig || {};

const mockType = params.targetType + 's';
Expand Down
6 changes: 3 additions & 3 deletions src/cli/facade/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ const publish =

logger.warn(strings.messages.cli.ENTER_USERNAME);

read({}, (err, username) => {
read({}, (_err, username) => {
logger.warn(strings.messages.cli.ENTER_PASSWORD);

read({ silent: true }, (err, password) => {
read({ silent: true }, (_err, password) => {
cb(null, { username, password });
});
});
Expand Down Expand Up @@ -110,7 +110,7 @@ const publish =

logger.warn(strings.messages.cli.REGISTRY_CREDENTIALS_REQUIRED);

return getCredentials((err, credentials) => {
return getCredentials((_err, credentials) => {
putComponentToRegistry(_.extend(options, credentials), cb);
});
} else if ((err as any).code === 'cli_version_not_valid') {
Expand Down
2 changes: 1 addition & 1 deletion src/cli/facade/registry-ls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Logger } from '../logger';

const registryLs =
({ registry, logger }: { logger: Logger; registry: RegistryCli }) =>
(opts: unknown, callback: Callback<string[], string>): void => {
(_opts: unknown, callback: Callback<string[], string>): void => {
registry.get((err, registries) => {
if (err) {
logger.err(strings.errors.generic(err));
Expand Down
2 changes: 1 addition & 1 deletion src/cli/facade/registry.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const registry =
() =>
(opts: unknown, callback: Callback<'ok'>): void => {
(_opts: unknown, callback: Callback<'ok'>): void => {
callback(null, 'ok');
};

Expand Down
2 changes: 1 addition & 1 deletion src/registry/domain/options-sanitiser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function optionsSanitiser(input: Input): Config {
const options = _.clone(input);

if (!options.publishAuth) {
(options as Config).beforePublish = (req, res, next) => next();
(options as Config).beforePublish = (_req, _res, next) => next();
} else {
(options as Config).beforePublish = auth.middleware(options.publishAuth);
}
Expand Down
2 changes: 1 addition & 1 deletion src/registry/domain/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ export default function repository(conf: Config): Repository {

repository.getComponentVersions(
componentName,
(err, componentVersions) => {
(_err, componentVersions) => {
if (
!versionHandler.validateNewVersion(
componentVersion,
Expand Down
2 changes: 1 addition & 1 deletion src/registry/middleware/cors.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NextFunction, Request, Response } from 'express';

export default function cors(
req: Request,
_req: Request,
res: Response,
next: NextFunction
): void {
Expand Down
2 changes: 1 addition & 1 deletion src/registry/middleware/file-uploads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default function fileUpload(
},
storage: multer.diskStorage({
destination: res.conf.tempDir,
filename: (req, file, cb) =>
filename: (_req, file, cb) =>
cb(null, `${normaliseFileName(file.originalname)}-${Date.now()}.tar.gz`)
})
});
Expand Down
2 changes: 1 addition & 1 deletion src/registry/middleware/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const bind = (app: Express, options: Config): Express => {
app.set('port', options.port);
app.set('json spaces', 0);

app.use((req, res, next) => {
app.use((_req, res, next) => {
res.conf = options;
next();
});
Expand Down
2 changes: 1 addition & 1 deletion src/registry/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function create(
const prefix = conf.prefix;

if (prefix !== '/') {
app.get('/', (req, res) => res.redirect(prefix));
app.get('/', (_req, res) => res.redirect(prefix));
app.get(prefix.substr(0, prefix.length - 1), routes.index);
}

Expand Down
7 changes: 4 additions & 3 deletions src/registry/routes/component-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ function componentInfo(
req: Request,
res: Response,
component: Component
) {
): void {
if (err) {
res.errorDetails = (err as any).registryError || err;
return res.status(404).json(err);
res.status(404).json(err);
return;
}

const isHtmlRequest =
Expand All @@ -63,7 +64,7 @@ function componentInfo(
typeof component.repository === 'string' ? component.repository : null
);

isUrlDiscoverable(href, (err, result) => {
isUrlDiscoverable(href, (_err, result) => {
if (!result.isDiscoverable) {
href = `//${req.headers.host}${res.conf.prefix}`;
}
Expand Down
5 changes: 3 additions & 2 deletions src/registry/routes/component-preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ function componentPreview(
if (err) {
res.errorDetails = err.registryError || err;
res.errorCode = 'NOT_FOUND';
return res.status(404).json(err);
res.status(404).json(err);
return;
}

let liveReload = '';
Expand All @@ -26,7 +27,7 @@ function componentPreview(
!!req.headers.accept && req.headers.accept.indexOf('text/html') >= 0;

if (isHtmlRequest && !!res.conf.discovery) {
return res.send(
res.send(
previewView({
component,
href: res.conf.baseUrl,
Expand Down
8 changes: 4 additions & 4 deletions src/registry/routes/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default function components(
const registryErrors = strings.errors.registry;

const returnError = function (message: string) {
return res.status(400).json({
res.status(400).json({
code: registryErrors.BATCH_ROUTE_BODY_NOT_VALID_CODE,
error: registryErrors.BATCH_ROUTE_BODY_NOT_VALID(message)
});
Expand All @@ -51,9 +51,9 @@ export default function components(
if (!_.isEmpty(components)) {
const errors = _.compact(
_.map(components, (component, index) => {
if (!component.name) {
return registryErrors.BATCH_ROUTE_COMPONENT_NAME_MISSING(index);
}
return !component.name
? registryErrors.BATCH_ROUTE_COMPONENT_NAME_MISSING(index)
: '';
})
);

Expand Down
2 changes: 1 addition & 1 deletion src/registry/routes/dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Config } from '../../types';
import getAvailableDependencies from './helpers/get-available-dependencies';

export default function dependencies(conf: Config) {
return function (req: Request, res: Response): void {
return function (_req: Request, res: Response): void {
if (res.conf.discovery) {
const dependencies = getAvailableDependencies(conf.dependencies).map(
({ core, name, version }) => {
Expand Down
2 changes: 1 addition & 1 deletion src/registry/routes/helpers/get-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ export default function getComponent(conf: Config, repository: Repository) {
repository.getCompiledView(
component.name,
component.version,
(err, templateText) => {
(_err, templateText) => {
let ocTemplate;

try {
Expand Down
2 changes: 1 addition & 1 deletion src/registry/routes/helpers/is-url-discoverable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default function isUrlDiscoverable(
url,
headers: { accept: 'text/html' }
},
(err, body, details) => {
(err, _body, details) => {
const isHtml = () =>
details.response.headers['content-type'].indexOf('text/html') >= 0;

Expand Down
3 changes: 2 additions & 1 deletion src/registry/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export default function (repository: Repository) {
repository.getComponents((err, components) => {
if (err) {
res.errorDetails = 'cdn not available';
return res.status(404).json({ error: res.errorDetails });
res.status(404).json({ error: res.errorDetails });
return;
}

const baseResponse = {
Expand Down
2 changes: 1 addition & 1 deletion src/registry/routes/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Request, Response } from 'express';
import { Config } from '../../types';

export default function plugins(conf: Config) {
return (req: Request, res: Response): void => {
return (_req: Request, res: Response): void => {
if (res.conf.discovery) {
const plugins = Object.entries(conf.plugins).map(
([pluginName, pluginFn]) => ({
Expand Down
7 changes: 3 additions & 4 deletions src/registry/routes/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@ export default function publish(repository: Repository) {
extractPackage(files, (err, pkgDetails) => {
if (err) {
res.errorDetails = `Package is not valid: ${err}`;
return res
.status(500)
.json({ error: 'package is not valid', details: err });
res.status(500).json({ error: 'package is not valid', details: err });
return;
}

repository.publishComponent(
Expand All @@ -85,7 +84,7 @@ export default function publish(repository: Repository) {
}
}

res.status(200).json({ ok: true });
return res.status(200).json({ ok: true });
}
);
});
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@
"useUnknownInCatchVariables": true /* Type catch clause variables as 'unknown' instead of 'any'. */,
"alwaysStrict": true /* Ensure 'use strict' is always emitted. */,
"noUnusedLocals": true /* Enable error reporting when a local variables aren't read. */,
// "noUnusedParameters": true /* Raise an error when a function parameter isn't read */,
"noUnusedParameters": true /* Raise an error when a function parameter isn't read */,
// "exactOptionalPropertyTypes": true /* Interpret optional property types as written, rather than adding 'undefined'. */,
// "noImplicitReturns": true /* Enable error reporting for codepaths that do not explicitly return in a function. */,
"noImplicitReturns": true /* Enable error reporting for codepaths that do not explicitly return in a function. */,
"noFallthroughCasesInSwitch": true /* Enable error reporting for fallthrough cases in switch statements. */,
// "noUncheckedIndexedAccess": true /* Include 'undefined' in index signature results */,
"noImplicitOverride": true /* Ensure overriding members in derived classes are marked with an override modifier. */,
Expand Down