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

Inconsistent use of T[] and Array<T> for arrays #1980

Closed
ckcherry23 opened this issue Apr 7, 2023 · 0 comments · Fixed by #2084
Closed

Inconsistent use of T[] and Array<T> for arrays #1980

ckcherry23 opened this issue Apr 7, 2023 · 0 comments · Fixed by #2084

Comments

@ckcherry23
Copy link
Member

What feature(s) would you like to see in RepoSense

Standardize the style used for arrays to be T[] or Array<T>, based on the complexity of T.

Is the feature request related to a problem?

During the TypeScript migration of the front-end, both of these styles were used interchangeably. Since the 2 styles are functionally equivalent, we can use the same style consistently across the codebase to make it easier for developers to read and understand array types.

If possible, describe the solution

  • Add a lint rule to enforce that the same array style is used across the code base. This should be in the global .eslintrc.json.

    We can consider using the array-simple option as this allows us to use the shorter, modern T[] or readonly T[] for simple types (i.e. types that are just primitive names or type references), and Array<T> or ReadonlyArray<T> for all other types (union types, intersection types, object types, function types, etc) where the shorter syntax could get confusing.

{
  "rules": {
    "@typescript-eslint/array-type": ["error", {
        "default": "array-simple",
        "readonly": "array-simple"
      }
    ]
  }
}
  • Make edits to the codebase such that the newly introduced lint rule is followed. Most of the changes will be in the props and data() sections of the .vue files.

If applicable, describe alternatives you've considered

We could also consider using the array or generic options for the lint rule if we want to stick to a single style at all times, no matter the complexity of the type.

Additional context

Discussed in #1976

@sopa301 sopa301 self-assigned this Jan 20, 2024
ckcherry23 pushed a commit that referenced this issue Jan 31, 2024
Array<T> and T[] can be used interchangeably in TypeScript. We can use
the same style consistently across the codebase to make it easier for
developers to read and understand array types.

In Vue, using T[] in defineComponent requires casting in the form of
"Array as PropType<T[]>", while Array<T> can be used as is. Therefore,
it would be more consistent to use Array<T> for .vue files.
Additionally, such a rule can be enforced more easily with eslint.

Let's include a rule for eslint to check array usage and change the
code to follow this rule.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Closed/Completed
Development

Successfully merging a pull request may close this issue.

2 participants