Finds the
package.json
a source file belongs to.
import getPackage from '@clark/eslint-util-get-package';
export const rules = {
'some-rule': {
create(context) {
const fileName = context.getFilename();
const packageJSON = getPackage(fileName);
if (!packageJSON)
throw new Error(
`Could not find a 'package.json' that '${fileName}' belongs to.`,
);
console.log(`'${fileName}' belongs to ${packageJSON.name}.`);
// ...
},
},
};