Skip to content
This repository has been archived by the owner on Dec 2, 2022. It is now read-only.

Latest commit

 

History

History

get-package






CLARK




@clark/eslint-util-get-package

Node CI code style: prettier CLARK Open Source

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}.`);

      // ...
    },
  },
};