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

It's a bit hard to set up using flat config style #155

Open
vandriesh opened this issue Jan 7, 2025 · 1 comment
Open

It's a bit hard to set up using flat config style #155

vandriesh opened this issue Jan 7, 2025 · 1 comment

Comments

@vandriesh
Copy link

Can any share their config ?

const youDontNeedMomentJS = require('eslint-plugin-you-dont-need-momentjs');
...
module.exports = [
    ...,
    {
        files: ['**/*.ts', '**/*.tsx', '**/*.js', '**/*.jsx'],
        plugins: {
            'you-dont-need-momentjs': youDontNeedMomentJS,
        },
        rules: {
            ...youDontNeedMomentJS.configs.recommended.rules,
        },
    },
];
TypeError: Error while loading rule 'you-dont-need-momentjs/no-dynamic-import-moment': Rule must be an object with a `create` method
Occurred while linting /Users/vandries/my-repos/.../eslint.config.js

TypeError: Error while loading rule 'you-dont-need-momentjs/no-dynamic-import-moment': Rule must be an object with a `create` method
Occurred while linting /Users/vandries/my-repos/.../eslint.config.js

does it meant it's not compatibil with flat approach ?

@vandriesh
Copy link
Author

ended up with:

{
        files: ['**/*.ts', '**/*.tsx', '**/*.js', '**/*.jsx'],
        plugins: {
            'you-dont-need-momentjs': youDontNeedMomentJS,
        },
        rules: {
            // Manually register each rule to ensure they follow flat config expectations
            ...Object.fromEntries(
                Object.entries(youDontNeedMomentJS.rules).map(([key, rule]) => [
                    `you-dont-need-momentjs/${key}`,
                    rule && rule.create ? 'warn' : 'off', // Apply if rule has a create method
                ]),
            ),
        },
    },
'you-dont-need-momentjs/no-dynamic-import-moment': 'off',
        'you-dont-need-momentjs/no-import-moment': 'off',
        'you-dont-need-momentjs/no-moment-constructor': 'off',
        'you-dont-need-momentjs/no-require-moment': 'off',
        'you-dont-need-momentjs/seconds': 'error',
        ...
        'you-dont-need-momentjs/is-date': 'error'

few fules has no create method - so I set off (AI suggestion) to use the rest of rules

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