Skip to content

🚀 Feature: Store just a message string and data in cache, not the full message object #149

Description

@JoshuaKGoldberg

Feature Request Checklist

Overview

Right now, the node_modules/.cache/flint.json data for a file with a report looks something like:

"packages/plugin-flint/src/rules/duplicateTests.test.ts": {
	"dependencies": [
		"packages/plugin-flint/src/rules/duplicateTests.ts",
		"packages/plugin-flint/src/rules/ruleTester.ts",
		"tsconfig.json"
	],
	"reports": [
		{
			"about": {
				"id": "forInArrays",
				"preset": "logical"
			},
			"message": {
				"primary": "For-in loops over arrays have surprising behavior that often leads to bugs.",
				"secondary": [
					"A for-in loop (`for (const i in o)`) iterates over all enumerable properties of an object, including those that are not array indices.",
					"This can lead to unexpected behavior when used with arrays, as it may include properties that are not part of the array's numeric indices.",
					"It also returns the index key (`i`) as a string, which is not the expected numeric type for array indices."
				],
				"suggestions": [
					"Use a construct more suited for arrays, such as a for-of loop (`for (const i of o)`)."
				]
			},
			"range": {
				"begin": {
					"column": 0,
					"line": 60,
					"raw": 1449
				},
				"end": {
					"column": 22,
					"line": 60,
					"raw": 1471
				}
			}
		}
	],
	"timestamp": 1752268964662
},

Note the "about" and "message" properties. They store a bunch of metadata about the rule. We could get a much smaller cache size if we just stored the rule ID, message ID string, and any interpolated message data. Roughly:

"packages/plugin-flint/src/rules/duplicateTests.test.ts": {
	"dependencies": [
		"packages/plugin-flint/src/rules/duplicateTests.ts",
		"packages/plugin-flint/src/rules/ruleTester.ts",
		"tsconfig.json"
	],
	"reports": [
		{
			"message": {
				"id": "forIn"
			},
			"range": {
				"begin": {
					"column": 0,
					"line": 60,
					"raw": 1449
				},
				"end": {
					"column": 22,
					"line": 60,
					"raw": 1471
				}
			},
			"rule": {
				"plugin": "ts",
				"rule": "forInArrays"
			}
		}
	],
	"timestamp": 1752268964662
}

Additional Info

❤️‍🔥

Metadata

Metadata

Assignees

No one assigned

    Labels

    package: coreRelated to the core Flint package underlying all other packages and plugins.status: accepting prsPlease, send a pull request to resolve this! 🙏type: featureNew enhancement or request 🚀

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions