prefer_interpolation_to_compose_strings
使用插值来组合字符串和值。
详情
#优先使用插值来组合字符串和值。
在组合字符串和值时,使用插值通常比字符串连接更容易编写和阅读。
差
dart
'Hello, ' + person.name + ' from ' + person.city + '.';
好
dart
'Hello, ${person.name} from ${person.city}.'
启用
#要启用 prefer_interpolation_to_compose_strings
规则,请在你的 analysis_options.yaml
文件中,在 linter > rules 下添加 prefer_interpolation_to_compose_strings
analysis_options.yaml
yaml
linter:
rules:
- prefer_interpolation_to_compose_strings
如果你使用 YAML 映射语法来配置 linter 规则,请在 linter > rules 下添加 prefer_interpolation_to_compose_strings: true
analysis_options.yaml
yaml
linter:
rules:
prefer_interpolation_to_compose_strings: true