| 141 | } |
| 142 | |
| 143 | func writeJSON(path string, data map[string]any) error { |
| 144 | if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil { |
| 145 | return fmt.Errorf("editorconfig: mkdir %s: %w", filepath.Dir(path), err) |
| 146 | } |
| 147 | encoded, err := json.MarshalIndent(data, "", " ") |
| 148 | if err != nil { |
| 149 | return fmt.Errorf("editorconfig: marshal %s: %w", path, err) |
| 150 | } |
| 151 | encoded = append(encoded, '\n') |
| 152 | if err := os.WriteFile(path, encoded, 0o600); err != nil { |
| 153 | return fmt.Errorf("editorconfig: write %s: %w", path, err) |
| 154 | } |
| 155 | return nil |
| 156 | } |