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

chore: unused exports linter and fixing #2130

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
35 changes: 29 additions & 6 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,57 @@
"es6": true,
"jest": true
},
"plugins": ["@typescript-eslint"],
"plugins": ["@typescript-eslint", "eslint-plugin-import"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"prettier",
"prettier/@typescript-eslint"
"prettier/@typescript-eslint",
"plugin:import/recommended",
"plugin:import/typescript"
],
"rules": {
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-empty-function": "warn",

// non-null assertions compromise the type safety somewhat, but many
// our types are still imprecisely defined and we don't use noImplicitAny
// anyway, so for the time being assertions are allowed
"@typescript-eslint/no-non-null-assertion": "warn",

"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/no-unused-vars": "error",
"no-prototype-builtins": "off",
"require-atomic-updates": "off",
"no-restricted-imports": [
"error",
{ "paths": ["lodash"], "patterns": ["lodash/*"] }
{
"paths": ["lodash"],
"patterns": ["lodash/*"]
}
],
"no-buffer-constructor": "error"
"no-buffer-constructor": "error",
"import/namespace": "off",
"import/no-unused-modules": [
"error",
{
"unusedExports": true
}
]
},
"settings": {
"import/parsers": {
"@typescript-eslint/parser": [".ts", ".tsx"]
},
"import/resolver": {
"node": {
"extensions": [".js"]
},
"typescript": {
"alwaysTryTypes": true
}
}
},
"overrides": [
{
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'],
};
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,16 @@
"@types/sinon": "^7.5.0",
"@types/update-notifier": "^4.1.0",
"@typescript-eslint/eslint-plugin": "2.18.0",
"@typescript-eslint/parser": "^2.0.0",
"@typescript-eslint/parser": "^2.34.0",
"ajv": "^6.12.6",
"cross-spawn": "^6.0.5",
"danger": "^10.6.4",
"depcheck": "^1.4.1",
"eslint": "6.8.0",
"eslint-config-prettier": "^6.1.0",
"eslint-import-resolver-node": "^0.3.4",
"eslint-import-resolver-typescript": "^2.4.0",
"eslint-plugin-import": "^2.23.4",
"fs-extra": "^9.1.0",
"jest": "^26.6.3",
"jest-junit": "^12.0.0",
Expand Down
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
Loading