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

Clean dlint flags #15290

Merged
merged 4 commits into from
Oct 25, 2022
Merged

Clean dlint flags #15290

merged 4 commits into from
Oct 25, 2022

Conversation

akrmn
Copy link
Contributor

@akrmn akrmn commented Oct 19, 2022

This cleans up a few issues I found when looking at the lint-related options. The main ones are:

  1. damlc commands that don't care about lint options no longer accept any lint options.
  2. It is now possible to specify the "base" rules file by its full path (rather than the path of its containing directory with the file being forced to have the name dlint.yaml).
  3. It is now possible to specify multiple concrete hints files ("overrides") rather than just having the option of the implicit .dlint.yaml from the closest ancestor or the user's home directory.
  4. damlc lint no longer accepts options to enable/disable linting.
  5. Parsed values of optDlintUsage are no longer overridden by the compiler anywhere.

@akrmn akrmn changed the title wip [WIP] Clean dlint flags Oct 19, 2022
@akrmn akrmn force-pushed the clean-lint-flags branch 4 times, most recently from 590362a to e099263 Compare October 20, 2022 12:38
changelog_begin
changelog_end
else
return Nothing
dlintSettings :: DlintUsage -> IO ([Classify], Hint)
dlintSettings DlintDisabled = pure ([], mempty @Hint)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

dlintSettings now works with DlintUsage instead of just the fields in DlintEnabled, so it can return the empty settings for DlintDisabled

Copy link
Collaborator

Choose a reason for hiding this comment

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

Naive question. Do we need the @Hint here ?

Comment on lines 1256 to +1257
defineNoFile $ \GetDlintSettings ->
liftIO $ case usage of
DlintEnabled dir enableOverrides -> dlintSettings dir enableOverrides
DlintDisabled -> fail "linter configuration unspecified"
liftIO $ dlintSettings usage
Copy link
Contributor Author

Choose a reason for hiding this comment

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

now GetDlintSettings can't fail

Comment on lines +1227 to +1231
getDlintRulesFile :: DlintRulesFile -> IO FilePath
getDlintRulesFile = \case
DefaultDlintRulesFile -> locateRunfiles $
mainWorkspace </> "compiler" </> "damlc" </> "daml-ide-core" </> "dlint.yaml"
ExplicitDlintRulesFile path -> pure path
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Previously dlintSettings simply got dlintDataDir :: FilePath as an argument, so all callers had to set the value to something, 99% of the time to the result of locateRunfiles $ mainWorkspace </> "compiler" </> "damlc" </> "daml-ide-core". Now, dlintSettings does a single lookup instead when dlintRulesFile = DefaultDlintRulesFile.

Comment on lines -1232 to +1224
(dlintDataDir </> "dlint.yaml") : maybeToList dlintYaml
dlintRulesFile : hintFiles
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since the only reason for dlintDataDir was to find the dlint.yaml file directly inside it, now we just talk about the file directly. This has the benefit of allowing users to specify any file as the rules file instead of having to name it dlint.yaml and specify the directory

@@ -152,9 +151,9 @@ runShakeTest = runShakeTestOpts id
-- | Run shake test on freshly initialised shake service, with custom options.
runShakeTestOpts :: (Daml.Options -> Daml.Options) -> Maybe SS.Handle -> ShakeTest () -> IO (Either ShakeTestError ShakeTestResults)
runShakeTestOpts fOpts mbScenarioService (ShakeTest m) = do
dlintDataDir <-locateRunfiles $ mainWorkspace </> "compiler/damlc/daml-ide-core"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we no longer need to locateRunfiles here

Comment on lines -631 to -637
setDlintDataDir :: Options -> IO Options
setDlintDataDir opts = do
defaultDir <-locateRunfiles $
mainWorkspace </> "compiler/damlc/daml-ide-core"
return $ case optDlintUsage opts of
DlintEnabled _ _ -> opts
DlintDisabled -> opts{optDlintUsage=DlintEnabled defaultDir True}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

now that cmdLint only allows the user to change the configuration of the linter, but not to turn it off, we don't need to hardcode these

@@ -726,8 +762,7 @@ execRepl dars importPkgs mbLedgerConfig mbAuthToken mbAppId mbSslConf mbMaxInbou
-- We change directory so make this absolute
dars <- mapM makeAbsolute dars
opts <- pure opts
{ optDlintUsage = DlintDisabled
Copy link
Contributor Author

Choose a reason for hiding this comment

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

now that cmdRepl forbids any linter flags, we don't need to hardcode it off here.

numProcessors
(EnableScenarioService False)
optPackageName
disabledDlintUsageParser
Copy link
Contributor Author

Choose a reason for hiding this comment

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

no linter flags for daml damlc docs

Comment on lines +313 to +315
fromParsed
<$> lastOr def (enableDlint <|> disableDlint)
<*> dlintOptionsParser
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Parsing the on/off flags separately from the options keeps the parser simple

@@ -196,8 +196,6 @@ getIntegrationTests registerTODO scenarioService = do
let outdir = "compiler/damlc/output"
createDirectoryIfMissing True outdir

dlintDataDir <- locateRunfiles $ mainWorkspace </> "compiler/damlc/daml-ide-core"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another place where we no longer need to locateRunfiles

Comment on lines +274 to +280
clearDlintHintFiles =
flag' NoDlintHintFiles
( long "lint-no-hint-files"
<> internal
<> help "Use no hint files for linting. This also ignores any \
\implicit '.dlint.yaml' files"
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since --lint-hint-file above allows multiple files to be specified, it's useful to have a way to clear them

@akrmn akrmn changed the title [WIP] Clean dlint flags Clean dlint flags Oct 20, 2022
@akrmn akrmn marked this pull request as ready for review October 20, 2022 14:27
@akrmn akrmn requested review from a team October 20, 2022 14:27
Copy link
Collaborator

@remyhaemmerle-da remyhaemmerle-da left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks.

@akrmn akrmn merged commit 0dbc042 into main Oct 25, 2022
@akrmn akrmn deleted the clean-lint-flags branch October 25, 2022 14:12
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.

None yet

2 participants