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

Add rule to remove interpolated strings #156

Merged
merged 3 commits into from
Nov 25, 2023

Conversation

jeparlefrancais
Copy link
Contributor

@jeparlefrancais jeparlefrancais commented Nov 24, 2023

Closes #92

This new rule replaces interpolated strings with string.format calls. The rule has a strategy property that defines how it converts the interpolated strings.

The default strategy "string" uses the %s string specifier in string.format calls and wrap each interpolated value in a tostring call.

The other available strategy is tostring, which uses the %* string specifier in string.format. This strategy does not need to wrap interpolated values.

Example:

local _ = `{object}`
-- generates:
local _ = tostring(object)
local _ = `Value = {object}`
-- generates:
local _ = string.format("Value = %s", tostring(object))
-- or generates with the `tostring` strategy:
local _ = string.format("Value = %*", object)

Todo:

  • add entry to the changelog
  • add rule docs

Copy link

Coverage after merging remove-interpolated-str-rule into main will be

87.08%

Coverage Report for Changed Files
FileStmtsBranchesFuncsLinesUncovered Lines
src
   parser.rs99.15%100%73.33%99.38%37, 43, 507–513, 55–59, 66
src/nodes
   arguments.rs86.81%100%85.71%87.14%130–131, 153–157, 159, 189, 57–59, 87–89
src/nodes/expressions
   interpolated_string.rs81.09%100%79.49%81.55%136–139, 164–167, 198–201, 203, 231–233, 306–312, 356–361, 386–389, 48–50, 76–79
src/process
   scope_visitor.rs81.70%100%76.92%82.65%132, 164–167, 180–190, 195, 219–221, 227–229, 249–251, 259–261
src/rules
   mod.rs89.03%100%77.78%90.49%105–107, 111, 121–123, 141–143, 145, 176–178, 264, 305–306, 341–343, 406–408, 66
   remove_interpolated_string.rs90.59%100%79.17%92.13%13, 211–218

@jeparlefrancais jeparlefrancais merged commit 9ac592f into main Nov 25, 2023
6 checks passed
@jeparlefrancais jeparlefrancais deleted the remove-interpolated-str-rule branch November 25, 2023 17:11
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.

Remove interpolated strings
1 participant