Code Monkey home page Code Monkey logo

Comments (7)

mxxk avatar mxxk commented on June 14, 2024 1

This is still an issue, so mentioning @idahogurl @JounQin for visibility

from prettier-eslint.

mxxk avatar mxxk commented on June 14, 2024

Posting some more findings with regards to "Aside 2" above:

Aside 2: ESLint appears to ignore .cjs files when run with .

After debugging via npx eslint . --debug, this appears to be the effect of the --ext CLI flag. Since . is a directory target, the implicit --ext .js takes effect and .cjs files are ignored:

$ npx eslint . --debug
eslint:file-enumerator Didn't match: example.cjs
eslint:file-enumerator Yield: example.js

On the contrary, ESLint file targets are included unconditionally:

$ npx eslint example.cjs example.js --debug
eslint:file-enumerator File: /repo/example.cjs
eslint:file-enumerator File: /repo/example.js

Since --ext has no direct configuration file equivalent (see eslint/eslint#2274 and eslint/eslint#11223), and the CLI docs state

  • Default Value: .js and the files that match the overrides entries of your configuration.

a no-op overrides item can be used to make ESLint consider .cjs files:

module.exports = {
  overrides: [
    { files: '*.cjs' },
  ],
};

This can be confirmed by rerunning eslint --debug:

$ npx eslint . --debug
eslint:file-enumerator Yield: example.cjs
eslint:file-enumerator Yield: example.js

The prettier-eslint issue persists, though...

I was hoping that the above change to ESLint configuration could serve as a workaround for the prettier-eslint formatting inconsistency, but unfortunately the formatting inconsistency is still reproducible.

from prettier-eslint.

github-actions avatar github-actions commented on June 14, 2024

Stale issue

from prettier-eslint.

mxxk avatar mxxk commented on June 14, 2024

No issue activity due to lack of response from maintainers

from prettier-eslint.

idahogurl avatar idahogurl commented on June 14, 2024

@mxxk Try putting this in your ESLint config

extensions: '[.js',
    '.jsx',
    '.ts',
    '.tsx',
    '.cjs',
    '.mjs',
    '.vue']

from prettier-eslint.

mxxk avatar mxxk commented on June 14, 2024

Thanks @idahogurl, but if I understood your suggestion correctly, extensions is not a valid top-level property in ESLint config (.eslintrc.*). Using the repro example above,

$ npx eslint example.cjs example.js

Oops! Something went wrong! :(

ESLint: 8.31.0

Error: ESLint configuration in .eslintrc.cjs is invalid:
	- Unexpected top-level property "extensions".

    at ConfigValidator.validateConfigSchema (/repo/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2156:19)
    at ConfigArrayFactory._normalizeConfigData (/repo/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2998:19)
    at ConfigArrayFactory.loadInDirectory (/repo/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2866:33)
    at CascadingConfigArrayFactory._loadConfigInAncestors (/repo/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3848:46)
    at CascadingConfigArrayFactory.getConfigArrayForFile (/repo/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3769:18)
    at FileEnumerator._iterateFilesWithFile (/repo/node_modules/eslint/lib/cli-engine/file-enumerator.js:368:43)
    at FileEnumerator._iterateFiles (/repo/node_modules/eslint/lib/cli-engine/file-enumerator.js:349:25)
    at FileEnumerator.iterateFiles (/repo/node_modules/eslint/lib/cli-engine/file-enumerator.js:299:59)
    at iterateFiles.next (<anonymous>)
    at CLIEngine.executeOnFiles (/repo/node_modules/eslint/lib/cli-engine/cli-engine.js:786:48)

Digging a little more, according to eslint/eslint#1674, eslint/eslint#2274, and eslint/eslint#10828, ESLint does not support a config file equivalent to passing --ext to the ESLint CLI.

from prettier-eslint.

idahogurl avatar idahogurl commented on June 14, 2024

@mxxk You're right. It will have to be fixed in the code. The extension needs to be added to this array.

const eslintExtensions = eslintConfig.extensions || [
'.js',
'.jsx',
'.ts',
'.tsx',
'.mjs',
'.vue'
];

from prettier-eslint.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.