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

Code style, scalafix, and scalafmt discussion. #3597

Open
lordspacehog opened this issue Mar 20, 2024 · 1 comment
Open

Code style, scalafix, and scalafmt discussion. #3597

lordspacehog opened this issue Mar 20, 2024 · 1 comment
Assignees
Labels

Comments

@lordspacehog
Copy link

lordspacehog commented Mar 20, 2024

Expanding on the discussion happening in #3593 here.

discussion summary
I'd like to propose reducing/removing wildcard imports where we can. It generally helps with presenting context and making the side effects of implicits more explicit.

Possible Options for wildcards:

  1. Be explicit until we hit some threshold then coalesce to wildcard
  2. always be explicit about imports but configure scalafmt to make them more compact. Also provide info on import folding for IDEs.
  3. Be explicit about imports, and if we use a lot from some other code base, namespace the useage of those things instead of wildcard importing.

In any of the above scenarios i think at a minimum we should move to explicitly importing implicits that are use just for clarity and potential safety.

As part of this i think we should also start figuring out a consistent set of guidelines and scalafix/fmt rules for this project.

The goal is to ease code maintenance burdens and do a big clean up on the project to get it all into a consistent style. Overall these changes help with readability as well.

Below is the basic scalafix config i've been using to help me clean up imports.

rules = [
//  RemoveUnused,
  DisableSyntax,
  LeakingImplicitClassVal,
  NoAutoTupling,
  NoValInForComprehension,
  ProcedureSyntax,
  OrganizeImports,
]


// OrganizeImports Config
OrganizeImports {
    blankLines = Auto
    groups = [
    "chisel3.",
    "hardfloat.",
    "org.chipsalliance.",
    "freechips.rocketchip.",
    "scala.",
    "scala.meta.",
    "*"
    ]
    groupedImports = Merge
    groupExplicitlyImportedImplicitsSeparately = true
    coalesceToWildcardImportThreshold = null
    expandRelative = true
    removeUnused = false
  }

@jerryrzhao @sequencer would greatly appreciate your ideas/input here.

Type of issue: other enhancement

Impact: no functional change

Development Phase: proposal

@jerryz123
Copy link
Contributor

To follow up on the discussion from the previous thread, I agree with @sequencer 's proposal

I'm proposing an alignment for rocket-chip that: we can add import package._ for chisel3, chisel3.utils, diplomacy., cde., since these libraries are quite common and really to exist as a library. For other busips(subsystem, rocketcore) I personally wanna have a explicit importing, but will also respect others suggestions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants