Skip to content

[Feature]: Allow @jest-environment pragma to be below other comments#12573

Description

@Josh-Cena

馃殌 Feature Proposal

Allow the

/**
 * @jest-environment jsdom
 */

To not be strictly the first comment node.

Motivation

Docusaurus has a very strict eslint header config that only allows:

/**
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

Unfortunately, the header plugin doesn't allow optional lines yet: Stuk/eslint-plugin-header#9 Which means we either have to add an empty line to all existing headers, so that we can have one line to accomodate the @jest-environment jsdom:

/**
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 */

// File without jsdom
/**
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 * @jest-environment jsdom
 */

// File with jsdom

Or we resort to a super-ugly compromise of allowing extra characters on the last line:

/**
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 * @jest-environment jsdom */

Or we disable the eslint rule for this file, which is definitely not desirable.

Or we implement that feature in the eslint plugin, but the plugin... unfortunately seems dead.

In the end, I think this would be a useful yet (I hope) simple feature to add in Jest.

Example

Allow this:

/**
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */
/**
 * @jest-environment jsdom
 */

Pitch

Flow allows the @flow pragma anywhere:

/**
 * Copyright (c) Facebook, Inc. and its affiliates.
 */
/**
 * @flow
 */
/**
 * Copyright (c) Facebook, Inc. and its affiliates.
 */
// @flow

And I think parsing a few extra comment nodes shouldn't be technically hard...

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions