Skip to content

Allow ignoring certain paths from sorting #211

@JoshuaKGoldberg

Description

@JoshuaKGoldberg

👋 I'm a big fan of this plugin and use it in http://github.com/JoshuaKGoldberg/template-typescript-node-package to sort package.json contents. Thanks for making it!

Turns out sometimes package.json content ordering does matter. Per https://www.typescriptlang.org/docs/handbook/esm-node.html#packagejson-exports-imports-and-self-referencing, the types resolution under "exports" > "." must come first:

// package.json
{
    "exports": {
        ".": {
            // Entry-point for TypeScript resolution - must occur first!
            "types": "./types/index.d.ts",
            // Entry-point for `import "my-package"` in ESM
            "import": "./esm/index.js",
            // Entry-point for `require("my-package") in CJS
            "require": "./commonjs/index.cjs",
        },
    }
}

Would you be open to a config option allowing to exclude certain object property paths? Maybe:

module.exports = {
	overrides: [
		{
			files: "*.json",
			parser: "jsonc-eslint-parser",
			rules: {
				"jsonc/sort-keys": [
					"error",
					{
						ignore: ["exports", "."],
					},
				],
			},
		},
	],
};

...I'm not confident in that ignore: string[] format. But can't think of a better option right now. 🤔

Potentially relevant: typescript-eslint/typescript-eslint#6017

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions