Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Restructure environmentVariablesUsed detection to avoid falsely alerting #1196

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

Open
blast-hardcheese wants to merge 1 commit into bash-lsp:main
base: main
Choose a base branch
Loading
from blast-hardcheese:dstewart/bug/incorrectly-warning-on-shfmt-envvar-usage
Open
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
18 changes: 14 additions & 4 deletions server/src/config.ts
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,20 @@
},
}

const environmentVariablesUsed = Object.entries(rawConfig)
.map(([key, value]) => (typeof value !== 'undefined' ? key : null))
.filter((key): key is string => key !== null)
.filter((key) => key !== 'logLevel') // logLevel is a special case that we ignore
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we filter out shfmt here like we already filter out loglevel?

Copy link
Author

@blast-hardcheese blast-hardcheese Sep 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personal preference, if I'm honest. I trend towards exhaustivity checks, where possible, but I'm happy to switch it back to the way it was and add a test to the filter.

const getUsedEnvvars = (rawConfigComponent: {[key: string]: any}): string[] => {

Check failure on line 104 in server/src/config.ts

View workflow job for this annotation

GitHub Actions / verify (16.x)

Replace `[key:·string]:·any` with `·[key:·string]:·any·`

Check failure on line 104 in server/src/config.ts

View workflow job for this annotation

GitHub Actions / verify (18.x)

Replace `[key:·string]:·any` with `·[key:·string]:·any·`

Check failure on line 104 in server/src/config.ts

View workflow job for this annotation

GitHub Actions / verify (20.x)

Replace `[key:·string]:·any` with `·[key:·string]:·any·`
return Object.entries(rawConfigComponent)
.map(([key, value]) => (typeof value !== 'undefined' ? key : null))
.filter((key): key is string => key !== null)
.filter((key) => key !== 'logLevel') // logLevel is a special case that we ignore
};

Check failure on line 109 in server/src/config.ts

View workflow job for this annotation

GitHub Actions / verify (16.x)

Delete `;`

Check failure on line 109 in server/src/config.ts

View workflow job for this annotation

GitHub Actions / verify (18.x)

Delete `;`

Check failure on line 109 in server/src/config.ts

View workflow job for this annotation

GitHub Actions / verify (20.x)

Delete `;`

// Since shfmt is structurally _always_ defined, we need to be careful to not
// incorrectly alert the user that they are doing something that needs to be
// changed.
//
// If other objects are added to rawConfig, please treat them similarly below.
const {shfmt, ... rest } = rawConfig;

Check failure on line 116 in server/src/config.ts

View workflow job for this annotation

GitHub Actions / verify (16.x)

Replace `shfmt,·...·rest·}·=·rawConfig;` with `·shfmt,·...rest·}·=·rawConfig`

Check failure on line 116 in server/src/config.ts

View workflow job for this annotation

GitHub Actions / verify (18.x)

Replace `shfmt,·...·rest·}·=·rawConfig;` with `·shfmt,·...rest·}·=·rawConfig`

Check failure on line 116 in server/src/config.ts

View workflow job for this annotation

GitHub Actions / verify (20.x)

Replace `shfmt,·...·rest·}·=·rawConfig;` with `·shfmt,·...rest·}·=·rawConfig`
const environmentVariablesUsed = getUsedEnvvars(rest).concat(getUsedEnvvars(shfmt));

Check failure on line 117 in server/src/config.ts

View workflow job for this annotation

GitHub Actions / verify (16.x)

Delete `;`

Check failure on line 117 in server/src/config.ts

View workflow job for this annotation

GitHub Actions / verify (18.x)

Delete `;`

Check failure on line 117 in server/src/config.ts

View workflow job for this annotation

GitHub Actions / verify (20.x)

Delete `;`

const config = ConfigSchema.parse(rawConfig)

Expand Down
Loading

AltStyle によって変換されたページ (->オリジナル) /