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

Settings are ignored using CLIEngine #4402

Closed
vanwagonet opened this issue Nov 12, 2015 · 5 comments
Closed

Settings are ignored using CLIEngine #4402

vanwagonet opened this issue Nov 12, 2015 · 5 comments
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion triage An ESLint team member will look at this issue soon

Comments

@vanwagonet
Copy link

I'm having trouble using the CLIEngine to create a cli tool for validating internationalization (via format-message).

I was able to create a plugin that works great when using the actual eslint cli, but cannot seem to getting settings to get through to the rules using CLIEngine. I have tried putting settings on both the root options object, as well as inside a baseConfig object, and either way context.settings is always an empty object inside my rules. I have not tried using configFile (which likely works), because the settings are dynamic, and I'd rather avoid writing a temp file just to pass settings.

Is there a way to pass the desired settings for use in cli.executeOnText?

Here is roughly the code I am using:

var cli = new CLIEngine({
  plugins: [ 'format-message' ],
  rules: {
    'format-message/literal-locale': 1,
    'format-message/literal-pattern': 1,
    'format-message/no-identical-translation': 1,
    'format-message/no-invalid-pattern': 2,
    'format-message/no-invalid-translation': 2,
    'format-message/no-missing-params': [ 2, { 'allowNonLiteral': true } ],
    'format-message/no-missing-translation': 1,
    'format-message/translation-match-params': 2
  },
  settings: {
    'format-message': {
      translations: { en: { foo: 'bar' } }
    }
  }
})
cli.executeOnText(...)
...
@eslintbot eslintbot added the triage An ESLint team member will look at this issue soon label Nov 12, 2015
@eslintbot
Copy link

Thanks for the issue! If you're reporting a bug, please be sure to include:

  1. The version of ESLint you are using (run eslint -v)
  2. What you did (the source code and ESLint configuration)
  3. The actual ESLint output complete with numbers
  4. What you expected to happen instead

Requesting a new rule? Please see Proposing a New Rule for instructions.

@vanwagonet
Copy link
Author

This is on eslint 1.9.0.

@gyandeeps
Copy link
Member

Have you tried this:

var cli = new CLIEngine({
    baseConfig: {
        plugins: [ 'format-message' ],
        rules: {
            'format-message/literal-locale': 1,
            'format-message/literal-pattern': 1,
            'format-message/no-identical-translation': 1,
            'format-message/no-invalid-pattern': 2,
            'format-message/no-invalid-translation': 2,
            'format-message/no-missing-params': [ 2, { 'allowNonLiteral': true } ],
            'format-message/no-missing-translation': 1,
            'format-message/translation-match-params': 2
        },
        settings: {
            'format-message': {
                translations: { en: { foo: 'bar' } }
            }
        }
    }
});

Here is the API docs: http://eslint.org/docs/developer-guide/nodejs-api#cliengine

@vanwagonet
Copy link
Author

\o/ That gets settings through! I could have sworn I tried that, but perhaps I had a typo in there 😕.

Thanks!

Now to figure out why I'm not seeing the lint errors I expect...

@arcanis
Copy link

arcanis commented Sep 23, 2016

Also got bitten by this issue - it's not really intuitive, maybe a console.warn would be helpful 😐

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 7, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Feb 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion triage An ESLint team member will look at this issue soon
Projects
None yet
Development

No branches or pull requests

4 participants