Open
Description
The use_truncating_division rule flags expressions where .toInt()
is called on the result of division. The documentation for toInt()
reads that it's the equivalent to truncate()
. However, the latter is not flagged by the linter rule:
void main() {
(42 / 9).toInt(); // Flagged
(42 / 9).truncate(); // Not flagged
}
analysis_options.yaml:
linter:
rules:
- use_truncating_division
dart analyze:
Analyzing dart_test_app... 0.5s
info • lib/main.dart:2:3 • Use truncating division. Try using truncating division, '~/', instead
of regular division ('/') followed by 'toInt()'. • use_truncating_division
1 issue found.
dart info
If providing this information as part of reporting a bug, please review the information
below to ensure it only contains things you're comfortable posting publicly.
#### General info
- Dart 3.8.1 (stable) (Wed May 28 00:47:25 2025 -0700) on "macos_arm64"
- on macos / Version 13.6 (Build 22G120)
- locale is en-RU
#### Project info
- sdk constraint: '>=3.5.0 <4.0.0'
- dependencies:
- dev_dependencies:
- elided dependencies: 1
#### Process info
| Memory | CPU | Elapsed time | Command line |
| -----: | ---: | -----------: | ------------------------------------------------------------------------------------------ |
| 23 MB | 0.0% | 03-08:09:36 | dart devtools --machine --dtd-uri=ws:<path>/NUrxQnYi8U09WOwZ |
| 13 MB | 0.0% | 02-22:41:12 | dart devtools --machine --dtd-uri=ws:<path>/RI_Yp5jMqwE= |
| 185 MB | 0.0% | 02:40 | dart language-server --client-id=Android-Studio --client-version=AI-241.15989.150 --protocol=analyzer |
| 25 MB | 0.0% | 02-22:41:12 | dart language-server --client-id=Android-Studio --client-version=AI-241.15989.150 --protocol=analyzer |
| 23 MB | 0.0% | 03-08:09:36 | dart tooling-daemon --machine |
| 57 MB | 0.0% | 02:40 | flutter_tools.snapshot daemon |
| 29 MB | 0.5% | 02-22:41:12 | flutter_tools.snapshot daemon |