Skip to content

Commit

Permalink
refactor: remove unused exports
Browse files Browse the repository at this point in the history
  • Loading branch information
teodora-sandu committed Aug 2, 2021
1 parent 4182444 commit 9918857
Show file tree
Hide file tree
Showing 47 changed files with 102 additions and 118 deletions.
6 changes: 2 additions & 4 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
}
],
"no-buffer-constructor": "error",
"import/no-unresolved": "error",
"import/namespace": "off",
"import/no-unused-modules": [
"error",
Expand All @@ -55,11 +54,10 @@
},
"import/resolver": {
"node": {
"extensions": [".js", ".jsx", ".ts", ".tsx"]
"extensions": [".js"]
},
"typescript": {
"alwaysTryTypes": true, // always try to resolve types under `<root>@types` directory
"project": "tsconfig.json"
"alwaysTryTypes": true
}
}
},
Expand Down
1 change: 1 addition & 0 deletions check-dependencies.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const config: Options = {
'@types/jest', // jest is a global so impossible to detect usage of types
'jest-junit', // used in circleci
'tap-junit', // used in circleci
'eslint-import-resolver-node', // used to find unused imports by Eslint
],
ignoreDirs: ['node_modules', 'dist', 'fixtures', 'test-output'],
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ interface NotSupported {
reason: string;
}

export function projectTypeSupported(
res: Supported | NotSupported,
): res is Supported {
function projectTypeSupported(res: Supported | NotSupported): res is Supported {
return !('reason' in res);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import { Workspace } from '../../../../types';
import { containsRequireDirective } from './contains-require-directive';

export interface PythonProvenance {
interface PythonProvenance {
[fileName: string]: ParsedRequirements;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ async function fixAll(
}

// TODO: optionally verify the deps install
export async function fixIndividualRequirementsTxt(
async function fixIndividualRequirementsTxt(
workspace: Workspace,
dir: string,
entryFileName: string,
Expand Down Expand Up @@ -166,7 +166,7 @@ export async function fixIndividualRequirementsTxt(
return { changes };
}

export async function applyAllFixes(
async function applyAllFixes(
entity: EntityToFix,
options: FixOptions,
): Promise<{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { isDefined } from './is-defined';
import { Requirement } from './requirements-file-parser';
import { standardizePackageName } from '../../../standardize-package-name';

export type FixesType = 'direct-upgrades' | 'transitive-pins';
type FixesType = 'direct-upgrades' | 'transitive-pins';

export function calculateRelevantFixes(
requirements: Requirement[],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ export async function updateDependencies(
return handlerResult;
}

export function generateSuccessfulChanges(
pins: DependencyPins,
): FixChangesSummary[] {
function generateSuccessfulChanges(pins: DependencyPins): FixChangesSummary[] {
const changes: FixChangesSummary[] = [];
for (const pkgAtVersion of Object.keys(pins)) {
const pin = pins[pkgAtVersion];
Expand Down
28 changes: 14 additions & 14 deletions packages/snyk-fix/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { CustomError } from './lib/errors/custom-error';
* this data is returned by the CLI plugins to identify
* what should be scanned for issues
*/
export interface GitTarget {
interface GitTarget {
remoteUrl: string;
branch: string;
}
export interface ContainerTarget {
interface ContainerTarget {
image: string;
}

Expand All @@ -28,7 +28,7 @@ export interface Identity {
args?: { [key: string]: string };
}

export interface Facts {
interface Facts {
type: string;
data: any;
}
Expand Down Expand Up @@ -78,26 +78,26 @@ export interface IssuesData {
/* Remediation Data
* this data is returned on a `snyk test` for supported project types
*/
export interface Upgrade {
interface Upgrade {
upgradeTo: string; // name@version
}

export interface UpgradeVulns extends Upgrade {
interface UpgradeVulns extends Upgrade {
vulns: string[];
}
export interface UpgradeRemediation extends UpgradeVulns {
interface UpgradeRemediation extends UpgradeVulns {
upgrades: string[];
}

export interface PatchRemediation {
interface PatchRemediation {
paths: PatchObject[];
}

export interface DependencyUpdates {
[from: string]: UpgradeRemediation;
}

export interface PinRemediation extends UpgradeVulns {
interface PinRemediation extends UpgradeVulns {
isTransitive: boolean;
}

Expand All @@ -117,7 +117,7 @@ export interface RemediationChanges {
pin: DependencyPins;
}

export interface IssueData {
interface IssueData {
id: string;
packageName: string;
version: string;
Expand Down Expand Up @@ -147,14 +147,14 @@ interface Patch {
modificationTime: string;
}

export enum REACHABILITY {
enum REACHABILITY {
FUNCTION = 'function',
PACKAGE = 'package',
NOT_REACHABLE = 'not-reachable',
NO_INFO = 'no-info',
}

export interface PatchObject {
interface PatchObject {
[name: string]: {
patched: string;
};
Expand All @@ -174,7 +174,7 @@ export enum SEVERITY {
* Types for concepts introduced as part of this lib
*/

export type SupportedScanTypes = 'pip';
type SupportedScanTypes = 'pip';

export interface Workspace {
path: string;
Expand All @@ -191,11 +191,11 @@ export interface EntityToFix {
// Partial CLI test options interface
// defining only what is used by @snyk/fix
// add more as needed
export interface PythonTestOptions {
interface PythonTestOptions {
command?: string; // python interpreter to use for python tests
dev?: boolean;
}
export type CliTestOptions = PythonTestOptions;
type CliTestOptions = PythonTestOptions;
export interface WithError<Original> {
original: Original;
error: CustomError;
Expand Down
5 changes: 1 addition & 4 deletions packages/snyk-fix/test/helpers/generate-entity-to-fix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,7 @@ function generateWorkspace(contents: string, path?: string) {
},
};
}
export function generateScanResult(
type: string,
targetFile: string,
): ScanResult {
function generateScanResult(type: string, targetFile: string): ScanResult {
return {
identity: {
type,
Expand Down
6 changes: 3 additions & 3 deletions packages/snyk-protect/src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ export type AnalyticsPayload = {
};
};

export type NoSnykFile = {
type NoSnykFile = {
type: ProtectResultType.NO_SNYK_FILE;
};

export type NothingToPatch = {
type NothingToPatch = {
type: ProtectResultType.NOTHING_TO_PATCH;
};

export type AppliedPatches = {
type AppliedPatches = {
type: ProtectResultType.APPLIED_PATCHES;
patchedModules: PatchedModule[];
};
Expand Down
2 changes: 1 addition & 1 deletion src/cli/commands/test/iac-local-execution/file-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function generateFailedParsedFile(
};
}

export function tryParseIacFile(
function tryParseIacFile(
fileData: IacFileData,
options: IaCTestFlags = {},
): IacFileParsed[] {
Expand Down
4 changes: 2 additions & 2 deletions src/cli/commands/test/iac-local-execution/file-scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class PolicyEngine {
}
}

export class FailedToBuildPolicyEngine extends CustomError {
class FailedToBuildPolicyEngine extends CustomError {
constructor(message?: string) {
super(message || 'Failed to build policy engine');
this.code = IaCErrorCodes.FailedToBuildPolicyEngine;
Expand All @@ -109,7 +109,7 @@ export class FailedToBuildPolicyEngine extends CustomError {
'We were unable run the test. Please run the command again with the `-d` flag and contact support@snyk.io with the contents of the output.';
}
}
export class FailedToExecutePolicyEngine extends CustomError {
class FailedToExecutePolicyEngine extends CustomError {
constructor(message?: string) {
super(message || 'Failed to execute policy engine');
this.code = IaCErrorCodes.FailedToExecutePolicyEngine;
Expand Down
3 changes: 1 addition & 2 deletions src/cli/commands/test/iac-local-execution/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ async function customRulesPathForOrg(

throw new FlagError('rules');
}

export function removeFileContent({
function removeFileContent({
filePath,
fileType,
failureReason,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type Awaited<T> = T extends PromiseLike<infer U> ? U : T;
// Note: The return type of the returned async function needs to be Promise<Val> for
// the compiler to be happy, so we need to unwrap it with the messy
// Awaiter<ReturnType<T>> rather than just using ReturnType<T> directly.
export function asyncPerformanceAnalyticsDecorator<
function asyncPerformanceAnalyticsDecorator<
T extends (...args: any[]) => Promise<any>
>(
measurableMethod: T,
Expand All @@ -33,9 +33,7 @@ export function asyncPerformanceAnalyticsDecorator<
};
}

export function performanceAnalyticsDecorator<
T extends (...args: any[]) => any
>(
function performanceAnalyticsDecorator<T extends (...args: any[]) => any>(
measurableMethod: T,
analyticsKey: PerformanceAnalyticsKey,
): (...args: Parameters<T>) => ReturnType<T> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function getIacOrgSettings(
});
}

export class FailedToGetIacOrgSettingsError extends CustomError {
class FailedToGetIacOrgSettingsError extends CustomError {
constructor(message?: string) {
super(message || 'Failed to fetch IaC organization settings');
this.code = IaCErrorCodes.FailedToGetIacOrgSettingsError;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { IacProjectType } from '../../../../../lib/iac/constants';
import { EngineType, IacFileData, IacFileParsed } from '../types';

export const REQUIRED_K8S_FIELDS = ['apiVersion', 'kind', 'metadata'];
export const REQUIRED_CLOUDFORMATION_FIELDS = ['Resources'];
const REQUIRED_K8S_FIELDS = ['apiVersion', 'kind', 'metadata'];
const REQUIRED_CLOUDFORMATION_FIELDS = ['Resources'];

export function detectConfigType(
fileData: IacFileData,
Expand Down Expand Up @@ -35,7 +35,7 @@ export function detectConfigType(
.filter((f): f is IacFileParsed => !!f);
}

export function checkRequiredFieldsMatch(
function checkRequiredFieldsMatch(
parsedDocument: any,
requiredFields: string[],
): boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export function tryParsingTerraformPlan(
}

// This error is due to the complex reduction logic, so it catches scenarios we might have not covered.
export class FailedToExtractResourcesInTerraformPlanError extends CustomError {
class FailedToExtractResourcesInTerraformPlanError extends CustomError {
constructor(message?: string) {
super(
message || 'Failed to extract resources from Terraform plan JSON file',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export function filterPoliciesBySeverity(
});
}

export class FailedToFormatResults extends CustomError {
class FailedToFormatResults extends CustomError {
constructor(message?: string) {
super(message || 'Failed to format results');
this.code = IaCErrorCodes.FailedToFormatResults;
Expand Down
2 changes: 1 addition & 1 deletion src/cli/commands/test/iac-local-execution/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface IacFileParseFailure extends IacFileData {
err: Error;
}

export type ScanningResults = {
type ScanningResults = {
scannedFiles: Array<IacFileScanResult>;
unscannedFiles: Array<IacFileParseFailure>;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export class TestLimitReachedError extends CustomError {

// Sub-interface of FormattedResult that we really only use to make test
// fixtures easier to create.
// eslint-disable-next-line import/no-unused-modules
export interface TrackableResult {
meta: {
isPrivate: boolean;
Expand Down
2 changes: 1 addition & 1 deletion src/cli/commands/test/iac-local-execution/yaml-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const errorsToSkip = [
// the YAML Parser is more strict than the Golang one in Policy Engine,
// so we decided to skip specific errors in order to be consistent.
// this function checks if the current error is one them
export function shouldThrowErrorFor(doc: YAML.Document.Parsed) {
function shouldThrowErrorFor(doc: YAML.Document.Parsed) {
return (
doc.errors.length !== 0 &&
!errorsToSkip.some((e) => doc.errors[0].message.includes(e))
Expand Down
4 changes: 2 additions & 2 deletions src/lib/analytics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ const snyk = require('../../lib');
const config = require('../config');
const version = require('../version');
import { makeRequest } from '../request';
const {
import {
getIntegrationName,
getIntegrationVersion,
getIntegrationEnvironment,
getIntegrationEnvironmentVersion,
getCommandVersion,
} = require('./sources');
} from './sources';
const isCI = require('../is-ci').isCI;
const debug = require('debug')('snyk');
const os = require('os');
Expand Down
2 changes: 1 addition & 1 deletion src/lib/analytics/sources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ function runCommand(cmd: string): Promise<string> {
});
}

export async function isInstalled(commandToCheck: string): Promise<boolean> {
async function isInstalled(commandToCheck: string): Promise<boolean> {
let whichCommand = 'which';
const os = process.platform;
if (os === 'win32') {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/find-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const debug = debugModule('snyk:find-files');
*
* @param path file path.
*/
export async function readDirectory(path: string): Promise<string[]> {
async function readDirectory(path: string): Promise<string[]> {
return await new Promise((resolve, reject) => {
fs.readdir(path, (err, files) => {
if (err) {
Expand All @@ -29,7 +29,7 @@ export async function readDirectory(path: string): Promise<string[]> {
*
* @param path path to file or directory.
*/
export async function getStats(path: string): Promise<fs.Stats> {
async function getStats(path: string): Promise<fs.Stats> {
return await new Promise((resolve, reject) => {
fs.stat(path, (err, stats) => {
if (err) {
Expand Down
Loading

0 comments on commit 9918857

Please sign in to comment.