Skip to content

Bug: flat config with "eslint:all" on a .cjs file recommends function form of "use strict" instead of global form #16304

@jzinn

Description

@jzinn

Environment

Node version: v16.14.0
npm version: 8.3.1
Local ESLint version: v8.23.1
Global ESLint version: zsh: command not found: eslint
Operating System: Fedora release 36 (Thirty Six)

What parser are you using?

Default (Espree)

What did you do?

package.json

Notice type is module.

{
  "devDependencies": {
    "eslint": "^8.23.1"
  },
  "license": "ISC",
  "name": "eslint-all-cjs",
  "scripts": {
    "lint": "eslint --fix ."
  },
  "type": "module",
  "version": "1.0.0"
}

eslint.config.js

Using the new flat config file format. The default languageOptions sourceType should be commonjs for .cjs files.

export default ["eslint:all"];

index.cjs

A .cjs file that ESLint should consider to be a commonjs file.

module.exports = function identity (value) {

    return value;

};

What did you expect to happen?

Expected: a message to use the global form of "use strict".

Why: the docs for rule strict say:

This rule has a string option:

  • "safe" (default) corresponds either of the following options:
    • "global" if ESLint considers a file to be a CommonJS module
    • "function" otherwise

The file ends with .cjs, so ESLint should recommend "global".

What actually happened?

A message to use the function form:

/path/to/eslint-all-cjs/index.cjs
  1:18  error  Use the function form of 'use strict'  strict

✖ 1 problem (1 error, 0 warnings)

Participation

  • I am willing to submit a pull request for this issue.

Additional comments

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    acceptedThere is consensus among the team that this change meets the criteria for inclusionarchived due to ageThis issue has been archived; please open a new issue for any further discussionbugESLint is working incorrectlyrepro:yesIssues with a reproducible exampleruleRelates to ESLint's core rules

    Type

    No type

    Projects

    Status

    Complete

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions