Skip to content

Conversation

@robertbrignull
Copy link
Contributor

@robertbrignull robertbrignull commented Aug 10, 2020

Depends on #140 so only the last commit is new to this PR.

This PR attempts to make language parsing more localised instead of being spred out over multiple places in multiple files. This should hopefully be a benefit if we ever add another offical language, or if codeql moves to fully 3rd-party extractors and we need to rethink languages entirely.

Also uses the Language type in more places, but thankfully all the call sites were already passing that type so it's all good.

Also starts using the import { foo } from './bar'; import syntax more. So far in this repository we've been exclusively doing import * as bar from './bar'; but I don't think there was any big reason for that.

Merge / deployment checklist

  • Confirm this change is backwards compatible with existing workflows.
  • Confirm the readme has been updated if necessary.

@robertbrignull robertbrignull changed the title Language parsing Refactor language parsing Aug 10, 2020
src/languages.ts Outdated
@@ -0,0 +1,39 @@
// All the languages supported by CodeQL
export const ALL_LANGUAGES = ['csharp', 'cpp', 'go', 'java', 'javascript', 'python'] as const;
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make more sense to use an enum here? eg-

enum Language {
  csharp = 'csharp',
  cpp = 'cpp',
  ... 
}

This would likely simplify the code somewhat and be more idiomatic typescript.

Copy link
Contributor Author

@robertbrignull robertbrignull Aug 17, 2020

Choose a reason for hiding this comment

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

The reason I did it this way was so you can check if something is part of the list at compiletime and runtime. According to https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-4.html#string-enums this isn't for string-valued enums. So I shouldn't be able to do something like if (language in Language)?

However, I tried it and added some tests (which I should have added from the start) and it works. So as far as I can tell it's all good. Do you agree?

@alexrford alexrford requested a review from a team August 20, 2020 15:16
Copy link
Contributor

@alexrford alexrford left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@mveytsman mveytsman left a comment

Choose a reason for hiding this comment

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

I love this! Great refactor and use of enums!

@robertbrignull robertbrignull merged commit 5d49d01 into main Aug 21, 2020
@robertbrignull robertbrignull deleted the language_parsing branch August 21, 2020 09:07
@github-actions github-actions bot mentioned this pull request Aug 24, 2020
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.

5 participants