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

Loading remarkrc.mjs with ESLint 'mdx/remark' option #300

Closed
4 tasks done
JulianCataldo opened this issue Oct 28, 2022 · 3 comments
Closed
4 tasks done

Loading remarkrc.mjs with ESLint 'mdx/remark' option #300

JulianCataldo opened this issue Oct 28, 2022 · 3 comments
Labels
👀 no/external This makes more sense somewhere else 👎 phase/no Post cannot or will not be acted on

Comments

@JulianCataldo
Copy link
Contributor

JulianCataldo commented Oct 28, 2022

Initial checklist

Affected packages and versions

latest

Steps to reproduce

Create a remarkrc.mjs config like:

import remarkFrontmatter from 'remark-frontmatter';
import remarkLintFrontmatterSchema from 'remark-lint-frontmatter-schema';

const remarkConfig = {
  plugins: [
    remarkFrontmatter,

    [
      remarkLintFrontmatterSchema,
      {
        schemas: {
          'content/articles/schemas/main.mdx.schema.yaml': [
            'content/articles/**/main.mdx',
          ],
        },
      },
    ],
  ],
};

export default remarkConfig;

When it's an MD file, pnpm remark . works, not when it's an MDX (it's normal).

So we need to treat MDX with ESLint which will read the remarkrc through the MDX plugin:

/** @type {import("@types/eslint").Linter.Config} */

module.exports = {
  overrides: [
    {
      files: ['*.mdx'],

      extends: ['plugin:mdx/recommended'],

      parserOptions: {
        ecmaVersion: 2015,
      },
      settings: {
        // Integration with remark-lint plugins
        'mdx/remark': true,
      },
    },
  ],
};

Only problem is that MJS file are not loaded by cosmic config.

It's blocking because all the unified eco-system is going 100% ESM, so we cannot convert our remark.mjs to a older remark.js or CJS:

// NOTE: ESLint loads remarkrc via cosmic config which doesn't support `.mjs`

module.exports = {
  plugins: [
    require('remark-frontmatter'),
    [
      require('remark-lint-frontmatter-schema'),
      {
        schemas: {
          'content/articles/schemas/main.mdx.schema.yaml': [
            'content/articles/**/main.mdx',
          ],
        },
      },
    ],
  ],
};

Expected behavior

Load MJS (optional: or even ts/mts?), like the remark lint cli / VS Code extension does.

Actual behavior

Mismatch between remark lint config when using MD versus MDX.

Side note:
Frontmatter schema plugin is incidentally working via remark cli but not the extension (this is normal, it doesn't parse the MD itself, just the frontmatter). But unfortunately I can't use this "bug" as a feature ;)

Maybe I'm missing something?
I could go with YAML / JSON configs maybe to circumvent those issues ? I admit it is not really an option as I need JS flexibility (like importing dynamically generated indexes…).

Cheers.

@github-actions github-actions bot added 👋 phase/new Post is being triaged automatically 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels Oct 28, 2022
@ChristianMurphy
Copy link
Member

ChristianMurphy commented Oct 28, 2022

Hey @JulianCataldo! 👋
Sorry you ran into a spot of trouble.

I'm not sure I follow your question.
remark-lint does not load configurations.
unified-engine does for the remark CLI command, and has supported ESM since version 8.2.0 https://github.com/unifiedjs/unified-engine/releases/tag/8.2.0

eslint-mdx does use cosmiconfig https://github.com/mdx-js/eslint-mdx/blob/829b6066bfd8dd05c366cf04fdb93e73d3ce2406/packages/eslint-plugin-mdx/README.md#mdxremark
to load configurations.

Only problem is that MJS file are not loaded by cosmic config

The cosmiconfig readme indicates there may be a way to load ESM https://github.com/davidtheclark/cosmiconfig

If that is not currently enabled in the eslint plugin, it would be something to raise and discuss there https://github.com/mdx-js/eslint-mdx/issues

Closing the issue here, as the issue is external to remark-lint

@ChristianMurphy ChristianMurphy closed this as not planned Won't fix, can't repro, duplicate, stale Oct 28, 2022
@ChristianMurphy ChristianMurphy added the 👀 no/external This makes more sense somewhere else label Oct 28, 2022
@github-actions

This comment has been minimized.

@github-actions github-actions bot added 👎 phase/no Post cannot or will not be acted on and removed 🤞 phase/open Post is being triaged manually labels Oct 28, 2022
@ChristianMurphy
Copy link
Member

If you haven't already, try eslint-mdx version 2, it looks like Joun added ESM support https://github.com/mdx-js/eslint-mdx/releases/tag/v2.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
👀 no/external This makes more sense somewhere else 👎 phase/no Post cannot or will not be acted on
Development

No branches or pull requests

2 participants