Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically configure sourceType for .js files #79

Open
phanect opened this issue Dec 26, 2023 · 0 comments
Open

Automatically configure sourceType for .js files #79

phanect opened this issue Dec 26, 2023 · 0 comments
Assignees

Comments

@phanect
Copy link
Owner

phanect commented Dec 26, 2023

"use strict";

const { autoConfig } = require("eslint-config-phanective");

module.exports = deepmerge({
  root: true,
  extends: "phanective/node",
  // ...
}, autoConfig(__dirname));

to set if .js files should be treated as a JSM or CommonJS.

module.exports = {
  autoConfig: async (projectRoot) => {
    const { type } = await readFile(join(projectRoot, "package.json"));

    return {
      overrides: [{
        files: [ "*.js", "**/*.js" ],
        parserOptions: {
          sourceType: (!type || type === "commonjs") ? "script" : "module",
        },
      }],
    };
  },
};
@phanect phanect self-assigned this Dec 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant