@clark/eslint-util-get-package

Finds the `package.json` a source file belongs to

Usage no npm install needed!

<script type="module">
  import clarkEslintUtilGetPackage from 'https://cdn.skypack.dev/@clark/eslint-util-get-package';
</script>

README






CLARK




@clark/eslint-util-get-package

Node CI code style: prettier dependencies devDependencies lerna 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}.`);

      // ...
    },
  },
};