A file mode is written as a decimal number that reads like octal, such as 644

tx0/go:decimal-file-modedefaultwarningbug

What it finds

os.WriteFile(path, data, 644): permission bits are read as octal by convention, but a literal without a leading 0 or 0o is decimal, so 644 is the mode 0o1204: no read bit for the owner, the sticky bit set, and write for others.

The mode must be a decimal integer literal of three or four digits that are all octal digits, given as the mode of os.Chmod, os.Mkdir, os.MkdirAll, os.WriteFile, os.OpenFile, ioutil.WriteFile, or converted with os.FileMode or fs.FileMode, resolved through the imports. Decimal values that are the usual modes written in decimal, such as 420 for 0o644 or 493 for 0o755, are left alone. The fix adds the 0o prefix, which changes the mode, so it is unsafe.

From the rule's source, decimal_file_mode.rs.

Example from the rule's tests
package p import "os" func f(path string, data []byte) error {	if err := os.WriteFile(path, data, 644); err != nil {tx0 reports: the mode 644 is decimal, which is 0o1204 in octal		return err	}	if err := os.MkdirAll(path, 0755); err != nil {		return err	}	if err := os.Chmod(path, 420); err != nil {		return err	}	_ = os.FileMode(600)tx0 reports: the mode 600 is decimal	return os.Mkdir(path, 0o700)}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:

tx0.toml
[rules]
"tx0/go:decimal-file-mode" = "off"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/go:decimal-file-mode] reason="..."

tx0 explain tx0/go:decimal-file-mode shows the same in the terminal. Found a false positive? Report it.