Skip to content

Print Width Whitelist should be optional #3706

Closed

Description

@tmquinn

or at the very least, whitelisted methods should be exposed through config.

I would LIKE my testing methods to be prettier-fied. Also, since 'skip' is not one of the whitelisted words, when my bot goes in to auto-skip flakey tests, all of a sudden I have tons of prettier lint errors.

Activity

  1. j-f1 commented on Jan 10, 2018

    @j-f1
    Member

    Can you go to the playground, paste in a sample of code that reproduces the behavior, then click on “Copy markdown” and paste the result into your issue description?

  2. added
    status:awaiting response
    on Jan 10, 2018
  3. tmquinn commented on Jan 10, 2018

    @tmquinn
    ContributorAuthor

    This is not an issue, specifically with a bad transform. It's related to

    function isTestCall(n) {

    #159
    #953

  4. j-f1 commented on Jan 10, 2018

    @j-f1
    Member

    Can you still fill out an example so we make sure to fix the right issue and also so we have a test to prevent regressions?

  5. tmquinn commented on Jan 10, 2018

    @tmquinn
    ContributorAuthor

    To clarify, this would be more categorized as a critical feature request rather than a bug. I believe Prettier is performing as intended, I just don't like it's intentions... I will still attempt to include some sort of output.

  6. tmquinn commented on Jan 10, 2018

    @tmquinn
    ContributorAuthor

    Prettier 1.10.1
    Playground link

    Input:

    test('this is a really long description of some test I want to go here', function (assert) {
      assert('herp-derp');
    })

    Output:

    test("this is a really long description of some test I want to go here", function(assert) {
      assert("herp-derp");
    });

    Expected behavior:
    This is the expected behavior

  7. tmquinn commented on Jan 10, 2018

    @tmquinn
    ContributorAuthor

    Prettier 1.10.1
    Playground link

    Input:

    skip('this is a really long description of some test I want to go here', function (assert) {
      assert('herp-derp');
    })

    Output:

    skip(
      "this is a really long description of some test I want to go here",
      function(assert) {
        assert("herp-derp");
      }
    );

    Expected behavior:
    This is how I want it to look, or at least have 'skip' added to the whitelist, or even better, expose the whitelist

  8. j-f1 commented on Jan 10, 2018

    @j-f1
    Member

    👍 Thanks for the examples!

    Maybe we should instead have it look for functions called with a string and a function. i.e. foo("test name", function () { /* test */ }).

    Also, note that test.skip works here:

    Prettier 1.10.1
    Playground link

    Input:

    test.skip('this is a really long description of some test I want to go here', function (assert) {
      assert('herp-derp');
    })

    Output:

    test.skip("this is a really long description of some test I want to go here", function(assert) {
      assert("herp-derp");
    });
  9. tmquinn commented on Jan 11, 2018

    @tmquinn
    ContributorAuthor

    yes, but test.skip is not a function of QUnit, while I would prefer to disable the whole whitelist, at the very least I would like to add skip() to it.

  10. azz commented on Jan 11, 2018

    @azz
    Member

    test.skip = skip?

  11. duailibe commented on Jan 11, 2018

    @duailibe
    Collaborator

    Maybe we should instead have it look for functions called with a string and a function. i.e. foo("test name", function () { /* test */ }).

    That is already one of the conditions (function call with 2 arguments: first a string, second a function).. The other one is if the callee matches some conditions

    function isTestCall(n) {
    const unitTestRe = /^(f|x)?(it|describe|test)$/;
    return (
    ((n.callee.type === "Identifier" && unitTestRe.test(n.callee.name)) ||
    (n.callee.type === "MemberExpression" &&
    n.callee.object.type === "Identifier" &&
    n.callee.property.type === "Identifier" &&
    unitTestRe.test(n.callee.object.name) &&
    (n.callee.property.name === "only" ||
    n.callee.property.name === "skip"))) &&
    n.arguments.length === 2 &&
    (n.arguments[0].type === "StringLiteral" ||
    n.arguments[0].type === "TemplateLiteral" ||
    (n.arguments[0].type === "Literal" &&
    typeof n.arguments[0].value === "string")) &&
    (n.arguments[1].type === "FunctionExpression" ||
    n.arguments[1].type === "ArrowFunctionExpression") &&
    n.arguments[1].params.length <= 1
    );
    }

  12. suchipi commented on Jan 11, 2018

    @suchipi
    Member

    I don't think a config option for this would be appropriate, but I think we could add support for a bare skip in unitTestRe, if that's common in QUnit.

    Somewhat related... I have been selfishly wishing that prettier formatted my describeComponent helper with the isTestCall logic, but it didn't seem appropriate to do for such a small library.

  13. j-f1 commented on Jan 11, 2018

    @j-f1
    Member

    @suchipi What do you think about my comment above?

    Maybe we should instead have it look for functions called with a string and a function. i.e. foo("test name", function () { /* test */ }).

  14. suchipi commented on Jan 11, 2018

    @suchipi
    Member

    I think that heuristic would hit too many false positives, eg:

    addListenerForPath("foo.bar", () => { /* ... */ });
  15. tmquinn commented on Jan 12, 2018

    @tmquinn
    ContributorAuthor

    @suchipi which of the config options do feel is not appropriate, printWidthWhitelist: 'disable', or having an printWidthWhitelistMethods: ['test', 'skip']

    Personally, I feel like this whole feature is a bit of a kludge, which is kinda surfaced by @azz's suggested workaround. Specifically I take issue with the arbitrariness of the whitelisted method names and the effort that is going to be required to keep this up to date for every user's setup. It seems to me that removing the internal printWidthWhitelist list, and making it 100% configurable as I mentioned above would make it more clear to users what is going on...

  16. suchipi commented on Jan 12, 2018

    @suchipi
    Member

    I don't think either config option is appropriate. A project goal of prettier is to have very few configuration options and be opinionated, but still work well despite the lack of configuration. The special-case formatting for tests is a very fine-grained and scoped feature, and it does not feel appropriate to add an option for such a specific case when we have rejected adding options for other more broad cases, such as adding a space between the keyword function and the parameter list.

    Prettier has chosen to format test methods this way because that's what users of jest, mocha, and jasmine requested, and often would have written by hand anyway. I recognize that the current behavior is inconsistent when using QUnit which is frustrating. I think the appropriate fix is to format skip like we do describe and it and etc, instead of making this behavior configurable.

  17. added
    help wanted
    lang:javascript
    and removed
    status:awaiting response
    on Jan 12, 2018
  18. azz commented on Jan 12, 2018

    @azz
    Member

    Well put, @suchipi.

    PRs to add skip(string, function) to the special case list welcome.

  19. added
    difficulty:easy
    on Jan 12, 2018
  20. tmquinn commented on Jan 12, 2018

    @tmquinn
    ContributorAuthor

    Hey, thanks for your response, I will submit a PR shortly.

    As a parting comment, I'd like to say that I love opinionated and appreciate it it's value. I agree that either config option would not be in the best interest of Prettier, but perhaps the feature itself should be re-evaluated. It seems to simply be // disable-prettier-ing based on an arbitrary and not particularly well documented list of methods. I believe that more users, such as myself, will be using test suites that Prettier will feel compelled to support. This adds overhead. In the absence of such curation, users will begin to implement workarounds, as mentioned above, or just fork the repo.

  21. added a commit that references this issue on Jan 13, 2018
  22. added
    locked-due-to-inactivity
    on Jul 6, 2018
  23. locked as resolved and limited conversation to collaborators on Jul 6, 2018
  24. added theissue type on Mar 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    difficulty:easyhelp wantedlang:javascriptlocked-due-to-inactivity

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions