Skip to content

Commit

Permalink
chore(dev-deps): update @automattic/eslint-plugin-wpvip to 0.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sjinks committed Sep 22, 2023
1 parent 6cbd6dc commit b792121
Show file tree
Hide file tree
Showing 20 changed files with 719 additions and 347 deletions.
947 changes: 657 additions & 290 deletions npm-shrinkwrap.json

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,9 @@
},
"homepage": "https://github.com/Automattic/vip#readme",
"devDependencies": {
"@automattic/eslint-plugin-wpvip": "0.5.8",
"@automattic/eslint-plugin-wpvip": "0.6.0",
"@babel/cli": "7.22.15",
"@babel/core": "7.22.17",
"@babel/eslint-parser": "7.22.10",
"@babel/plugin-transform-modules-commonjs": "7.22.15",
"@babel/preset-env": "7.22.15",
"@babel/preset-flow": "7.22.15",
Expand Down
7 changes: 1 addition & 6 deletions src/bin/vip-backup-db.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
#!/usr/bin/env node

/**
* @flow
* @format
*/

/**
* External dependencies
*/
Expand All @@ -15,7 +10,7 @@
import command from '../lib/cli/command';

import { makeCommandTracker } from '../lib/tracker';
import { App, AppEnvironment, Job } from '../graphqlTypes';
import { App, AppEnvironment } from '../graphqlTypes';
import { BackupDBCommand } from '../commands/backup-db';

const examples = [
Expand Down
2 changes: 1 addition & 1 deletion src/lib/analytics/clients/pendo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export default class Pendo implements AnalyticsClient {
properties: eventProps,
timestamp: Date.now(),
type: 'track',
visitorId: `${ this.context.userId! }`,
visitorId: `${ this.context.userId as string }`,
};

debug( 'send()', body );
Expand Down
1 change: 1 addition & 0 deletions src/lib/api/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { API_HOST } from '../../lib/api';
const debug = debugLib( '@automattic/vip:http' );

type FetchOptions = Omit< RequestInit, 'body' > & {
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
body?: BodyInit | Record< string, unknown >;
};

Expand Down
2 changes: 2 additions & 0 deletions src/lib/cli/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ const debug = debugLib( '@automattic/vip:lib:cli:config' );
let configFromFile: Config;
try {
// Get `local` config first; this will only exist in dev as it's npmignore-d.
// eslint-disable-next-line @typescript-eslint/no-var-requires
configFromFile = require( '../../../config/config.local.json' ) as Config;

debug( 'Loaded config data from config.local.json' );
} catch {
// Fall back to `publish` config file.
// eslint-disable-next-line @typescript-eslint/no-var-requires
configFromFile = require( '../../../config/config.publish.json' ) as Config;

debug( 'Loaded config data from config.publish.json' );
Expand Down
22 changes: 11 additions & 11 deletions src/lib/cli/progress.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
// @format

/**
* External dependencies
*/
import { EOL } from 'node:os';
import { stdout as singleLogLine } from 'single-line-log';

/**
* Internal dependencies
*/
import { getGlyphForStatus, RunningSprite } from '../../lib/cli/format';
import os from 'os';

const PRINT_INTERVAL = process.env.DEBUG ? 5000 : 200; // How often the report is printed. Mainly affects the "spinner" animation.

Expand Down Expand Up @@ -110,8 +108,10 @@ export class ProgressTracker {
status,
} ) );

if ( ! steps.some( ( { status } ) => status === 'running' ) ) {
const firstPendingStepIndex = steps.findIndex( ( { status } ) => status === 'pending' );
if ( ! steps.some( ( { status } ) => status === StepStatus.RUNNING ) ) {
const firstPendingStepIndex = steps.findIndex(
( { status } ) => status === StepStatus.PENDING
);

if ( firstPendingStepIndex !== -1 ) {
// "Promote" the first "pending" to "running"
Expand All @@ -127,7 +127,7 @@ export class ProgressTracker {
return undefined;
}
const steps = [ ...this.getSteps().values() ];
return steps.find( ( { status } ) => status === 'pending' );
return steps.find( ( { status } ) => status === StepStatus.PENDING );
}

getCurrentStep(): Step | undefined {
Expand All @@ -136,7 +136,7 @@ export class ProgressTracker {
}

const steps = [ ...this.getSteps().values() ];
return steps.find( ( { status } ) => status === 'running' );
return steps.find( ( { status } ) => status === StepStatus.RUNNING );
}

stepRunning( stepId: string ): void {
Expand All @@ -161,7 +161,7 @@ export class ProgressTracker {
}

allStepsSucceeded(): boolean {
return [ ...this.getSteps().values() ].every( ( { status } ) => status === 'success' );
return [ ...this.getSteps().values() ].every( ( { status } ) => status === StepStatus.SUCCESS );
}

setStatusForStepId( stepId: string, status: StepStatus ) {
Expand All @@ -175,7 +175,7 @@ export class ProgressTracker {
throw new Error( `Step name ${ stepId } is already completed.` );
}

if ( status === 'failed' ) {
if ( status === StepStatus.FAILED ) {
this.hasFailure = true;
}

Expand Down Expand Up @@ -221,7 +221,7 @@ export class ProgressTracker {
let linesToSkip = '';

for ( let iteration = 0; iteration < this.stepsFromCaller.size; iteration++ ) {
linesToSkip += os.EOL;
linesToSkip += EOL;
}

process.stdout.write( linesToSkip );
Expand Down Expand Up @@ -252,7 +252,7 @@ export class ProgressTracker {
const statusIcon = getGlyphForStatus( status, this.runningSprite );
let suffix = '';
if ( id === 'upload' ) {
if ( status === 'running' && percentage ) {
if ( status === StepStatus.RUNNING && percentage ) {
suffix = percentage;
}
} else if ( progress ) {
Expand Down
16 changes: 8 additions & 8 deletions src/lib/client-file-uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ import { MB_IN_BYTES } from '../lib/constants/file-size';
// Need to use CommonJS imports here as the `fetch-retry` typedefs are messed up and throwing TypeJS errors when using `import`
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const fetchWithRetry: ( input: RequestInfo | URL, init?: RequestInit ) => Promise< Response > =
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-var-requires
require( 'fetch-retry' )( fetch, {
// Set default retry options
retries: 3,
retryDelay: ( attempt: number, error: Error, response: Response ) => {
retryDelay: ( attempt: number ) => {
return Math.pow( 2, attempt ) * 1000; // 1000, 2000, 4000
},
} );
Expand Down Expand Up @@ -69,7 +69,7 @@ export interface GetSignedUploadRequestDataArgs {
| 'ListParts'
| 'PutObject'
| 'UploadPart';
etagResults?: Object[];
etagResults?: Record< string, unknown >[];
appId: number;
envId: number;
basename: string;
Expand All @@ -84,7 +84,7 @@ interface UploadArguments {
app: WithId;
env: WithId;
fileMeta: FileMeta;
progressCallback?: Function;
progressCallback?: ( percentage: string ) => unknown;
}

export const getFileMD5Hash = async ( fileName: string ): Promise< string > => {
Expand Down Expand Up @@ -215,7 +215,7 @@ interface UploadUsingArguments {
app: WithId;
env: WithId;
fileMeta: FileMeta;
progressCallback?: Function;
progressCallback?: ( percentage: string ) => unknown;
}

interface PresignedRequest {
Expand Down Expand Up @@ -271,7 +271,7 @@ async function uploadUsingPutObject( {

const response = await fetchWithRetry( presignedRequest.url, {
...fetchOptions,
body: fileContent ? fileContent : createReadStream( fileName ).pipe( progressPassThrough ),
body: fileContent ?? createReadStream( fileName ).pipe( progressPassThrough ),
} );

if ( response.status === 200 ) {
Expand Down Expand Up @@ -480,7 +480,7 @@ interface UploadPartsArgs {
fileMeta: FileMeta;
uploadId: string;
parts: Part[];
progressCallback?: Function;
progressCallback?: ( percentage: string ) => unknown;
}

export async function uploadParts( {
Expand Down Expand Up @@ -641,7 +641,7 @@ export interface CompleteMultipartUploadArgs {
env: WithId;
basename: string;
uploadId: string;
etagResults: Object[];
etagResults: Record< string, unknown >[];
}

/**
Expand Down
7 changes: 4 additions & 3 deletions src/lib/config/software.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,8 @@ export const promptForUpdate = async (

const confirm: boolean =
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
opts.force ||
opts.force || // NOSONAR
( await new Confirm( {
// NOSONAR
message: `Are you sure you want to upgrade ${ COMPONENT_NAMES[ component ] } to ${ version }?`,
} )
.run()
Expand Down Expand Up @@ -406,7 +405,9 @@ export const getUpdateResult = async ( appId: number, envId: number ): Promise<
}

const failedStep = completedJob.progress?.steps?.find( step => step?.status === 'failed' );
const error = failedStep ? `Failed during step: ${ failedStep.name! }` : 'Software update failed';
const error = failedStep
? `Failed during step: ${ failedStep.name as string }`
: 'Software update failed';
return {
ok: false,
errorMessage: error,
Expand Down
6 changes: 3 additions & 3 deletions src/lib/dev-environment/dev-environment-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import Lando from 'lando';
/**
* Internal dependencies
*/
import { ProgressTracker, Step, StepConstructorParam } from '../../lib/cli/progress';
import { ProgressTracker, StepConstructorParam } from '../../lib/cli/progress';
import { trackEvent } from '../tracker';

import {
Expand Down Expand Up @@ -252,7 +252,7 @@ export function getEnvironmentStartCommand(
return `${ DEV_ENVIRONMENT_FULL_COMMAND } start --slug ${ slug }`;
}

export function printTable( data: Object ) {
export function printTable( data: Record< string, unknown > ) {
const formattedData = formatters.formatData( data, { format: 'table' }, { border: false } );

console.log( formattedData );
Expand Down Expand Up @@ -687,7 +687,7 @@ export function resolvePhpVersion( version: string ): string {
result = images[ 0 ];
}
} else {
result = DEV_ENVIRONMENT_PHP_VERSIONS[ version ]!;
result = DEV_ENVIRONMENT_PHP_VERSIONS[ version ] as string;
}

debug( 'Resolved PHP image: %j', result );
Expand Down
2 changes: 1 addition & 1 deletion src/lib/dev-environment/dev-environment-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ function preProcessInstanceData( instanceData: InstanceData ): InstanceData {

newInstanceData.php =
instanceData.php ||
DEV_ENVIRONMENT_PHP_VERSIONS[ Object.keys( DEV_ENVIRONMENT_PHP_VERSIONS )[ 0 ] ]!;
( DEV_ENVIRONMENT_PHP_VERSIONS[ Object.keys( DEV_ENVIRONMENT_PHP_VERSIONS )[ 0 ] ] as string );
if ( newInstanceData.php.startsWith( 'image:' ) ) {
newInstanceData.php = newInstanceData.php.slice( 'image:'.length );
}
Expand Down
18 changes: 11 additions & 7 deletions src/lib/dev-environment/dev-environment-lando.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,12 @@ async function initLandoApplication( lando: Lando, instancePath: string ): Promi

app.events.on( 'post-init', 1, () => {
const initOnly: string[] = [];
Object.keys( app.config.services! ).forEach( serviceName => {
if ( app.config.services![ serviceName ].initOnly ) {
const services = app.config.services as Record< string, Lando.LandoService >;
Object.keys( services ).forEach( serviceName => {
if ( services[ serviceName ].initOnly ) {
initOnly.push( serviceName );
app.config.services![ serviceName ].scanner = false;
( app.config.services as Record< string, Lando.LandoService > )[ serviceName ].scanner =
false;
}
} );

Expand Down Expand Up @@ -162,7 +164,7 @@ async function getLandoApplication( lando: Lando, instancePath: string ): Promis
const started = new Date();
try {
if ( appMap.has( instancePath ) ) {
return Promise.resolve( appMap.get( instancePath )! );
return Promise.resolve( appMap.get( instancePath ) as App );
}

if ( ! ( await doesEnvironmentExist( instancePath ) ) ) {
Expand Down Expand Up @@ -305,7 +307,7 @@ async function getBridgeNetwork( lando: Lando ): Promise< NetworkInspectInfo | n
async function cleanUpLandoProxy( lando: Lando ): Promise< void > {
const network = await getBridgeNetwork( lando );
if ( network?.Containers && ! Object.keys( network.Containers ).length ) {
const proxy = lando.engine.docker.getContainer( lando.config.proxyContainer! );
const proxy = lando.engine.docker.getContainer( lando.config.proxyContainer as string );
try {
await proxy.remove( { force: true } );
} catch ( err ) {
Expand Down Expand Up @@ -561,7 +563,9 @@ export async function landoExec(
) {
const app = await getLandoApplication( lando, instancePath );

const tool = app.config.tooling![ toolName ] as Record< string, unknown > | undefined;
const tool = ( app.config.tooling as Record< string, Record< string, unknown > > )[ toolName ] as
| Record< string, unknown >
| undefined;
if ( ! tool ) {
throw new UserError( `${ toolName } is not a known lando task` );
}
Expand Down Expand Up @@ -672,7 +676,7 @@ async function removeVolume( lando: Lando, volumeName: string ): Promise< void >
* can safely add a network and a new proxy container.
*/
async function ensureNoOrphantProxyContainer( lando: Lando ): Promise< void > {
const proxyContainerName = lando.config.proxyContainer!;
const proxyContainerName = lando.config.proxyContainer as string;

const docker = lando.engine.docker;
const containers = await docker.listContainers( { all: true } );
Expand Down
1 change: 1 addition & 0 deletions src/lib/keychain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const debug = debugLib( '@automattic/vip:keychain' );

try {
// Try using Secure keychain ("keytar") first
// eslint-disable-next-line @typescript-eslint/no-var-requires
const Secure = require( './keychain/secure' ) as KeychainConstructor;
exportValue = new Secure();
} catch ( error ) {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/media-import/media-file-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ export function currentUserCanImportForApp( app: AppForMediaImport ): boolean {
export const SUPPORTED_MEDIA_FILE_IMPORT_SITE_TYPES = [ 'WordPress' ];

export const isSupportedApp = ( { type }: AppForMediaImport ) =>
SUPPORTED_MEDIA_FILE_IMPORT_SITE_TYPES.includes( type! );
SUPPORTED_MEDIA_FILE_IMPORT_SITE_TYPES.includes( type as string );
4 changes: 1 addition & 3 deletions src/lib/media-import/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ import {
currentUserCanImportForApp,
} from '../../lib/media-import/media-file-import';
import { MediaImportProgressTracker } from '../../lib/media-import/progress';
import { capitalize, formatEnvironment, formatData } from '../../lib/cli/format';

import { RunningSprite } from '../cli/format';
import { capitalize, formatEnvironment, formatData, RunningSprite } from '../../lib/cli/format';
import { AppQuery, AppQueryVariables } from './status.generated';
import {
App,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/site-import/db-file-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function currentUserCanImportForApp( app: App | AppForImport ): boolean {
}

export const isSupportedApp = ( { typeId }: AppForImport ) =>
DATABASE_APPLICATION_TYPE_IDS.includes( typeId! );
DATABASE_APPLICATION_TYPE_IDS.includes( typeId as number );

export const SYNC_STATUS_NOT_SYNCING = 'not_syncing';

Expand Down
6 changes: 3 additions & 3 deletions src/lib/site-import/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import debugLib from 'debug';
* Internal dependencies
*/
import API from '../../lib/api';
import { currentUserCanImportForApp } from '../../lib/site-import/db-file-import';
import { ProgressTracker, StepFromServer, StepStatus } from '../../lib/cli/progress';
import * as exit from '../../lib/cli/exit';
import { capitalize, formatEnvironment, getGlyphForStatus } from '../../lib/cli/format';
Expand All @@ -25,7 +24,7 @@ import {
Maybe,
PrimaryDomainSwitchJob,
} from '../../graphqlTypes';
import { AppForImport } from './db-file-import';
import { AppForImport, currentUserCanImportForApp } from './db-file-import';

const debug = debugLib( 'vip:lib/site-import/status' );

Expand Down Expand Up @@ -118,7 +117,8 @@ interface ImportFailedError {
inImportProgress: boolean;
commandOutput: string[] | null;
error: string;
stepName: 'import_preflights' | 'importing_db' | 'validating_db' | string;
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
stepName: 'import_preflights' | 'importing_db' | 'validating_db' | string; // NOSONAR
launched: boolean;
}

Expand Down
Loading

0 comments on commit b792121

Please sign in to comment.