Skip to content

Commit 8eef020

Browse files
committed
Updated .prettierrc to have 120 print width, updated eslint.config.js to ensure one-liners still are wrapped in {} curly braces
1 parent 451608d commit 8eef020

14 files changed

Lines changed: 48 additions & 119 deletions

File tree

.lintstagedrc.cjs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
module.exports = {
2-
'*.{ts,js,json,yml,yaml,md}': (filenames) =>
3-
filenames.map((filename) => `prettier --write '${filename}'`),
2+
'*.{ts,js,json,yml,yaml,md}': (filenames) => filenames.map((filename) => `prettier --write '${filename}'`),
43
'{src,test}/**/*.ts': (filenames) => {
54
if (filenames.length === 0) {
65
return [];

.prettierrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2+
"printWidth": 120,
23
"semi": true,
3-
"trailingComma": "es5",
44
"singleQuote": true,
5-
"printWidth": 100,
65
"tabWidth": 2,
6+
"trailingComma": "es5",
77
"useTabs": false
88
}

eslint.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import { defineConfig } from 'eslint/config';
33
import tseslint from 'typescript-eslint';
44

55
export default defineConfig([
6+
{
7+
ignores: ['lib/**'],
8+
},
69
{
710
files: ['src/**/*.ts', 'test/**/*.ts'],
811
extends: [
@@ -11,6 +14,9 @@ export default defineConfig([
1114
tseslint.configs.stylisticTypeChecked,
1215
tseslint.configs.recommendedTypeChecked,
1316
],
17+
rules: {
18+
curly: ['error', 'all'],
19+
},
1420
},
1521
{
1622
languageOptions: {

src/commands/dotenv/export.ts

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ const SFDX_PROJECT_FILE = 'sfdx-project.json';
2626
export default class DotEnvExport extends SfCommand<void> {
2727
public static pluginName = PLUGIN_NAME;
2828

29-
public static readonly summary =
30-
'Generate or update an .env file with "replaceWithEnv" entries in sfdx-project.json';
29+
public static readonly summary = 'Generate or update an .env file with "replaceWithEnv" entries in sfdx-project.json';
3130
public static readonly description =
3231
'Reads sfdx-project.json and writes any "replaceWithEnv" values from the "replacements" node to a .env file. ' +
3332
'If the output file already exists, only missing keys are appended.';
@@ -82,9 +81,7 @@ export default class DotEnvExport extends SfCommand<void> {
8281
const projectFilePath = path.resolve(process.cwd(), SFDX_PROJECT_FILE);
8382

8483
if (!fs.existsSync(projectFilePath)) {
85-
this.error(
86-
`Could not find ${SFDX_PROJECT_FILE} in the current directory (${process.cwd()}).`
87-
);
84+
this.error(`Could not find ${SFDX_PROJECT_FILE} in the current directory (${process.cwd()}).`);
8885
}
8986

9087
try {
@@ -154,11 +151,7 @@ export default class DotEnvExport extends SfCommand<void> {
154151
return { outputFilePath, existingContent, existingKeys };
155152
}
156153

157-
private getMissingKeys(
158-
environmentKeys: string[],
159-
existingKeys: Set<string>,
160-
outputFile: string
161-
): string[] | null {
154+
private getMissingKeys(environmentKeys: string[], existingKeys: Set<string>, outputFile: string): string[] | null {
162155
const missingKeys = environmentKeys.filter((k) => !existingKeys.has(k)).sort();
163156

164157
if (missingKeys.length === 0) {
@@ -193,11 +186,7 @@ export default class DotEnvExport extends SfCommand<void> {
193186
return envFileNewLines.join('\n');
194187
}
195188

196-
private writeEnvFile(
197-
outputFilePath: string,
198-
appendContent: string,
199-
existingContent: string
200-
): void {
189+
private writeEnvFile(outputFilePath: string, appendContent: string, existingContent: string): void {
201190
if (existingContent) {
202191
fs.appendFileSync(outputFilePath, appendContent, 'utf-8');
203192
} else {

src/commands/dotenv/inspect.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import { DEFAULT_ENV_PATH, displayLoadedEnvVars, getEnv, PLUGIN_NAME } from '../
44
export default class DotEnvInspect extends SfCommand<void> {
55
public static readonly summary =
66
'This plugin runs whenever another `sf` cli command is invoked, and loads environment variables into context.';
7-
public static readonly description =
8-
'Runs in the background - prints environment variables if invoked directly';
7+
public static readonly description = 'Runs in the background - prints environment variables if invoked directly';
98

109
public static pluginName = PLUGIN_NAME;
1110

src/hooks/prerun.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,7 @@ let shouldLog = true;
1616
* Check if the hook should be skipped based on command arguments
1717
*/
1818
function shouldSkipHook(argv: string[], pluginName?: string) {
19-
return (
20-
pluginName === PLUGIN_NAME ||
21-
argv.includes('--help') ||
22-
argv.includes('-h') ||
23-
argv[0] === 'dotenv'
24-
);
19+
return pluginName === PLUGIN_NAME || argv.includes('--help') || argv.includes('-h') || argv[0] === 'dotenv';
2520
}
2621

2722
/**
@@ -34,10 +29,7 @@ function isDotEnvDisabled() {
3429
/**
3530
* Display the loading message with environment variables (when not suppressed)
3631
*/
37-
function displayLoadingMessage(
38-
envConfig: { envFilePath: string; env: Record<string, string> },
39-
argv: string[]
40-
): void {
32+
function displayLoadingMessage(envConfig: { envFilePath: string; env: Record<string, string> }, argv: string[]): void {
4133
if (!shouldLog || argv.includes('--json')) {
4234
return;
4335
}
@@ -49,9 +41,7 @@ function displayLoadingMessage(
4941
*/
5042
function handleLoadError(error: unknown): void {
5143
if (shouldLog) {
52-
ux.warn(
53-
`Failed to load .env file: ${error instanceof Error ? error.message : 'Unknown error'}`
54-
);
44+
ux.warn(`Failed to load .env file: ${error instanceof Error ? error.message : 'Unknown error'}`);
5545
}
5646
}
5747

src/shared/configMeta.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import { CONFIG_SHOULD_LOG_KEY } from './constants.js';
55
export default [
66
{
77
key: CONFIG_SHOULD_LOG_KEY,
8-
description:
9-
'Whether or not to print out the loaded env variables prior to running any other SF CLI command',
8+
description: 'Whether or not to print out the loaded env variables prior to running any other SF CLI command',
109
input: {
1110
validator: (value: ConfigValue): boolean =>
1211
// eslint-disable-next-line @typescript-eslint/no-base-to-string

src/shared/environment.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,7 @@ function determineEnvFilePath(argv: string[], explicitPath?: string) {
2626
return { envFilePath: path.resolve(envFilePath), envFileIndex };
2727
}
2828

29-
async function validateEnvFile(
30-
envFilePath: string,
31-
envFileIndex: number,
32-
shouldLog: boolean
33-
): Promise<boolean> {
29+
async function validateEnvFile(envFilePath: string, envFileIndex: number, shouldLog: boolean): Promise<boolean> {
3430
if (!(await fs.pathExists(envFilePath))) {
3531
if (envFileIndex !== -1 && shouldLog) {
3632
ux.warn(`Environment file not found: ${envFilePath}`);
@@ -41,9 +37,7 @@ async function validateEnvFile(
4137
const stat = await fs.stat(envFilePath);
4238
if (!stat.isFile()) {
4339
if (shouldLog) {
44-
ux.warn(
45-
`${envFilePath} is a directory, not a file. Proceeding without loading environment variables.`
46-
);
40+
ux.warn(`${envFilePath} is a directory, not a file. Proceeding without loading environment variables.`);
4741
}
4842
return false;
4943
}
@@ -63,11 +57,7 @@ export interface EnvConfig {
6357
env: Record<string, string>;
6458
}
6559

66-
export const getEnv = async (
67-
argv: string[],
68-
shouldLog = false,
69-
explicitEnvFilePath?: string
70-
): Promise<EnvConfig> => {
60+
export const getEnv = async (argv: string[], shouldLog = false, explicitEnvFilePath?: string): Promise<EnvConfig> => {
7161
const { envFilePath, envFileIndex } = determineEnvFilePath(argv, explicitEnvFilePath);
7262
if (!(await validateEnvFile(envFilePath, envFileIndex, shouldLog))) {
7363
return { envFilePath: path.relative(process.cwd(), envFilePath), env: {} };

src/shared/loadingMessage.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ interface DisplayLoadedEnvVarsOptions {
1818
* When showValues is false: variable names only with checkmarks (prerun and `sf dotenv` without --show-values).
1919
* When showValues is true: key=value pairs with checkmarks, preceded by a security warning (all via ux).
2020
*/
21-
export function displayLoadedEnvVars(
22-
envConfig: EnvConfig,
23-
options: DisplayLoadedEnvVarsOptions
24-
): void {
21+
export function displayLoadedEnvVars(envConfig: EnvConfig, options: DisplayLoadedEnvVarsOptions): void {
2522
const loadedVars = Object.keys(envConfig.env);
2623
const loadedCount = loadedVars.length;
2724
if (loadedCount === 0) {
@@ -37,9 +34,7 @@ export function displayLoadedEnvVars(
3734

3835
if (options.showValues) {
3936
ux.warn(SENSITIVE_OUTPUT_WARNING);
40-
printedMessage = sortedEnvironmentKeys
41-
.map((key) => `${key}=${envConfig.env[key]}`)
42-
.join(DELIMITER);
37+
printedMessage = sortedEnvironmentKeys.map((key) => `${key}=${envConfig.env[key]}`).join(DELIMITER);
4338
}
4439
ux.stdout(`${header}${loadingLine}${DELIMITER}${printedMessage}`);
4540
}

test/commands/dotenv/export.test.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,7 @@ describe('dotenv export command', () => {
6666

6767
beforeEach(() => {
6868
jest.clearAllMocks();
69-
mockResolve.mockImplementation((...args: unknown[]) =>
70-
actualPath.resolve(...(args as [string, ...string[]]))
71-
);
69+
mockResolve.mockImplementation((...args: unknown[]) => actualPath.resolve(...(args as [string, ...string[]])));
7270
mockStatSync.mockReturnValue({ isDirectory: () => false });
7371
// Default: no project file (tests that need it override)
7472
mockExistsSync.mockReturnValue(false);
@@ -89,9 +87,7 @@ describe('dotenv export command', () => {
8987
it('errors with a clear message', async () => {
9088
mockExistsSync.mockReturnValue(false);
9189

92-
await expect(runCommand(['dotenv', 'export'])).rejects.toThrow(
93-
/Could not find sfdx-project\.json/
94-
);
90+
await expect(runCommand(['dotenv', 'export'])).rejects.toThrow(/Could not find sfdx-project\.json/);
9591

9692
expect(mockExistsSync).toHaveBeenCalled();
9793
expect(mockReadFileSync).not.toHaveBeenCalled();
@@ -103,9 +99,7 @@ describe('dotenv export command', () => {
10399
mockExistsSync.mockReturnValue(true);
104100
mockReadFileSync.mockReturnValue('not valid json {');
105101

106-
await expect(runCommand(['dotenv', 'export'])).rejects.toThrow(
107-
/Failed to parse sfdx-project\.json/
108-
);
102+
await expect(runCommand(['dotenv', 'export'])).rejects.toThrow(/Failed to parse sfdx-project\.json/);
109103
});
110104
});
111105

@@ -133,9 +127,7 @@ describe('dotenv export command', () => {
133127

134128
await cmd.run();
135129

136-
expect(logSpy).not.toHaveBeenCalledWith(
137-
'No "replaceWithEnv" entries found in sfdx-project.json. Nothing to do.'
138-
);
130+
expect(logSpy).not.toHaveBeenCalledWith('No "replaceWithEnv" entries found in sfdx-project.json. Nothing to do.');
139131
expect(mockWriteFileSync).not.toHaveBeenCalled();
140132
expect(mockAppendFileSync).not.toHaveBeenCalled();
141133
});

0 commit comments

Comments
 (0)