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

Switch from flatKeywordList() to flat arrays #676

Merged
merged 8 commits into from
Dec 1, 2023
Merged

Switch from flatKeywordList() to flat arrays #676

merged 8 commits into from
Dec 1, 2023

Conversation

karlhorky
Copy link
Contributor

@karlhorky karlhorky commented Nov 29, 2023

Part of preparations for PR #673

Copied from my original comment:

I see there is no distinction in the keyword tokens between all and dataType / datatype / dataTypes:

// https://www.postgresql.org/docs/14/sql-keywords-appendix.html
all: [
'ABORT',
'ABSOLUTE',
'ACCESS',

dataType: [
'DATALENGTH',
'IDENT_CURRENT',
'IDENT_INCR',
'IDENT_SEED',
'IDENTITY',

datatypes: [
'NUMBER',
'DECIMAL',
'NUMERIC',
'INT',

// Parameterized types
// https://docs.microsoft.com/en-us/sql/t-sql/data-types/data-types-transact-sql?view=sql-server-ver15
dataTypes: [
'DECIMAL',
'NUMERIC',
'FLOAT',
'REAL',

This is because of the flatKeywordList() function, which effectively discards the key information:

// Used for flattening keyword lists
export const flatKeywordList = (obj: Record<string, string[]>): string[] =>
dedupe(Object.values(obj).flat());

Because of this, I would like to simplify the src/languages/*/*.keywords.ts files to export 1 flat array (with empty lines + comments as separators instead of object keys) and delete the flatKeywordList() function - this will prevent unusual, inconsistent naming conventions and also clarify that the object keys do nothing.

Reviewer notes

  1. Best to review this with whitespace changes turned off: https://github.com/sql-formatter-org/sql-formatter/pull/676/files?w=1
  2. This PR also enables GitHub Actions workflows CI for pull requests on branches other than master and develop, so that PRs from community members can be tested on GitHub Actions
  3. while removing the object keys, I added comments as such:
    a. if there was a commented URL above the key, I removed the key and left the URL as the sole comment (eg. in src/languages/db2i/db2i.functions.ts)
    b. if there was no other comment (or if the commented URL was generic, for multiple sections), I left the key name as the comment (eg. in src/languages/hive/hive.functions.ts)

@nene
Copy link
Collaborator

nene commented Dec 1, 2023

Thanks 👍

@nene nene merged commit 8641a84 into sql-formatter-org:master Dec 1, 2023
1 check passed
@karlhorky
Copy link
Contributor Author

Glad to help, thanks for the review and merge!

@karlhorky karlhorky deleted the switch-from-flatKeywordList-to-flat-arrays branch December 1, 2023 10:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants