rule : Configuration -> Review.Rule.Rule
Reports usages of deprecated values and types.
config =
[ NoDeprecated.rule NoDeprecated.defaults
]
import DeprecatedModule
a =
DeprecatedModule.view "..."
b =
Button.view_DEPRECATED "Click me!" OnClick
I recommend making it extra explicit when deprecating elements in your application code, for instance by renaming them to include "deprecated" in their name, or in their module name for modules.
That way, it will be very clear for you and your teammates when you're using something that is deprecated, even in Git diffs.
For packages, renaming something is a breaking change so that is not a viable option (if it is, remove the function and release a new major version). Instead, what you can do is to start a line in your module/value/type's documentation with `
As mentioned before, this rule is recommended to be used with elm-review
's suppression system. One of its benefits,
is that the number of usages will be tallied per file in the <review>/suppressed/NoDeprecated.json
file. You can look
at it, and decide to tackle one file over another based on how many problems are in the file and how you prefer tackling
these issues.
While tackling issues file by file might work for some cases, sometimes it is nicer to organize work based on how often a deprecated function/type is used. For instance, you might want to look at the functions that are used only once or twice, or look at the functions that are the most widespread in your codebase.
To get this point of view, you can run this rule as an insight rule:
elm-review --report=json --extract --rules NoDeprecated | jq -r '.extracts.NoDeprecated'
which will yield a result like the following:
{
"Some.Deprecated.Module": {
"total": 28,
"isModuleDeprecated": true,
"usages": {
"someFunction": 20,
"someType": 8
}
},
"Some.Module": {
"total": 1,
"isModuleDeprecated": false,
"usages": {
"someDeprecatedFunction": 1
}
}
}
Configuration for the rule.
Create one using defaults
, then change it using functions like dependencies
and
withExceptionsForElements
.
defaults : Configuration
Default configuration.
By default are considered as deprecated:
Configure this further using functions like dependencies
and
withExceptionsForElements
.
dependencies : List String -> Configuration -> Configuration
Mark one or more dependencies as deprecated.
config =
[ NoDeprecated.defaults
|> NoDeprecated.dependencies [ "jfmengels/some-deprecated-dependency" ]
|> NoDeprecated.rule
]
Every usage of something defined in that dependency in the project's code wil be reported.
withExceptionsForElements : List String -> Configuration -> Configuration
Add exceptions for the reporting elements. This can for instance be used for values and that contain "deprecated" in their name without actually being deprecated.
config =
[ NoDeprecated.defaults
|> NoDeprecated.withExceptionsForElements [ "SomeModule.listOfDeprecatedFunctions" ]
|> NoDeprecated.rule
]
If you do not have deprecated elements in your project, this rule won't be useful.
You can try this rule out by running the following command:
elm-review --template jfmengels/elm-review-common/example --rules NoDeprecated