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

Incorrect documentation: object config #1016

Closed
tonyhallett opened this issue Apr 16, 2017 · 2 comments
Closed

Incorrect documentation: object config #1016

tonyhallett opened this issue Apr 16, 2017 · 2 comments

Comments

@tonyhallett
Copy link
Contributor

tonyhallett commented Apr 16, 2017

The information pertaining to option config and argument config needs to be changed in both Interacting with the user and in the API.

The type property of both configs can be a custom function with the argument config also accepting an actual array. It is much clearer to specify in this manner compared to how it is currently. For instance, for argument config it states 'String, Number, Array (can also be a custom function receiving the raw string value and parsing it)' this would be better served with Array, function(arg):actual

These custom functions do have different input types though as well as different defaults. The option config will always have the function called and so can be any type given that the default will be passed when the option is missing otherwise will be the provided value. The argument config will only be passed the raw string argument.

'use strict';
/* eslint no-unused-vars: ["error", { "varsIgnorePattern": "[iI]gnored" }] */
/* eslint max-params: ["error", 5] */

var Generator = require('yeoman-generator');

var helpers = require('yeoman-test');

var boolValue = true;
var defaultOptionValue = {someProp: 'someValue'};

var boolTypeFn = jest.fn(() => { });
var defaultFn = jest.fn(() => { });

var testGenerator = class extends Generator {
    // Supposedly this is unnecessary http://eslint.org/docs/rules/no-useless-constructor
    // http://eslint.org/docs/user-guide/configuring
  constructor(args, opts) {
    super(args, opts);
    this.option('boolOption', {type: boolTypeFn});
    this.option('defaultObjectOption', {default: defaultOptionValue, type: defaultFn});
  }
  initializing() {

  }

};

describe('documentation is incorrect on options config type property', () => {
  beforeAll(() => {
    return helpers.run(testGenerator)
          .withOptions({
            boolOption: boolValue
          })
          .withArguments([]);
  });

  it('receives the option value', () => {
    expect(boolTypeFn).toHaveBeenCalledWith(true);
  });
  it('receives the default value for an option that has not been provided', () => {
    expect(defaultFn).toHaveBeenCalledWith(defaultOptionValue);
  });
});
@tonyhallett tonyhallett changed the title Incorrect documentation Incorrect documentation: object config Apr 16, 2017
@SBoudrias
Copy link
Member

Feel free to send a PR.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 1, 2020

This issue is stale because it has been open 15 days with no activity. Remove stale label or comment or this will be closed in 5 days

@github-actions github-actions bot added the stale label Jan 1, 2020
@github-actions github-actions bot closed this as completed Jan 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants