Skip to content

Conversation

@aladdin-add
Copy link
Member

fixes #148

@aladdin-add aladdin-add changed the title feat: support lint json/markdown feat: support languages json/markdown Nov 4, 2024
importContent += "import pluginReact from \"eslint-plugin-react\";\n";
exportContent += " pluginReact.configs.flat.recommended,\n";
// the default is commonmark
exportContent += " {files: [\"**/*.md\"], language: \"markdown/gfm\"},\n";
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A better UX if it could export a predefined config for gfm?

]
}
];
Object.assign(this.answers, await enquirer.prompt(langQuestions));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didn't use skip - as there is a known issue when using multi-selection: enquirer/enquirer#298

@aladdin-add aladdin-add marked this pull request as ready for review November 5, 2024 01:48
@mdjermanovic
Copy link
Member

I think this part described in #148 isn't implemented:

The JavaScript option should be checked by default and if unchecked, we should add this to the config:

{
    ignores: ["**/*.js", "**/*.cjs", "**/*.mjs"]
}

@aladdin-add aladdin-add requested review from harish-sethuraman, mdjermanovic and nzakas and removed request for harish-sethuraman November 8, 2024 02:14
Co-authored-by: Milos Djermanovic <[email protected]>
Co-authored-by: Milos Djermanovic <[email protected]>
@mdjermanovic
Copy link
Member

A problem is that most plugin configs (including @eslint/js configs) don't have files, so they would apply to non-JS files.

For example:

$ npx @eslint/create-config
@eslint/create-config: v1.3.1

√ What do you want to lint? · javascript, json
√ How would you like to use ESLint? · problems    
√ What type of modules does your project use? · esm
√ Which framework does your project use? · none
√ Does your project use TypeScript? · no / yes
√ Where does your code run? · No items were selected
The config that you've selected requires the following dependencies:

eslint, @eslint/js, @eslint/json
√ Would you like to install them now? · No / Yes
√ Which package manager do you want to use? · npm
☕️Installing...

up to date, audited 363 packages in 1s

183 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
Successfully created C:\projects\tmp\tmp\eslint.config.mjs file.

Generated config file:

import pluginJs from "@eslint/js";
import json from "@eslint/json";


/** @type {import('eslint').Linter.Config[]} */
export default [
  pluginJs.configs.recommended,
  {files: ["**/*.json"], language: "json/json", ...json.configs.recommended},
];
$ npx eslint package.json

Oops! Something went wrong! :(

ESLint: 9.14.0

TypeError: Error while loading rule 'no-irregular-whitespace': sourceCode.getAllComments is not a function
Occurred while linting C:\projects\tmp\tmp\package.json
    at Object.create (C:\projects\tmp\tmp\node_modules\eslint\lib\rules\no-irregular-whitespace.js:87:41)
    at createRuleListeners (C:\projects\tmp\tmp\node_modules\eslint\lib\linter\linter.js:943:21)
    at C:\projects\tmp\tmp\node_modules\eslint\lib\linter\linter.js:1068:84
    at Array.forEach (<anonymous>)
    at runRules (C:\projects\tmp\tmp\node_modules\eslint\lib\linter\linter.js:999:34)
    at #flatVerifyWithoutProcessors (C:\projects\tmp\tmp\node_modules\eslint\lib\linter\linter.js:1911:31)
    at Linter._verifyWithFlatConfigArrayAndWithoutProcessors (C:\projects\tmp\tmp\node_modules\eslint\lib\linter\linter.js:1992:49)
    at Linter._verifyWithFlatConfigArray (C:\projects\tmp\tmp\node_modules\eslint\lib\linter\linter.js:2081:21)
    at Linter.verify (C:\projects\tmp\tmp\node_modules\eslint\lib\linter\linter.js:1528:61)
    at Linter.verifyAndFix (C:\projects\tmp\tmp\node_modules\eslint\lib\linter\linter.js:2319:29)

@aladdin-add aladdin-add marked this pull request as draft November 8, 2024 13:57
@aladdin-add
Copy link
Member Author

Yes, I was able to repro!

Is it the expected behavior? My understanding is that it should only be applied to js/mjs/cjs files if no files are specified.

and I'm getting the same error even if I added files:

import pluginJs from "@eslint/js";
import json from "@eslint/json";


/** @type {import('eslint').Linter.Config[]} */
export default [
  {files: ["**/*.{js,mjs,cjs}"]},
  pluginJs.configs.recommended,
  {files: ["**/*.json"], language: "json/json", ...json.configs.recommended},
];

@aladdin-add
Copy link
Member Author

given extends has been shipped, I'll update the pr to use it. 🎉

@aladdin-add aladdin-add self-assigned this Mar 10, 2025
@mdjermanovic
Copy link
Member

Is it the expected behavior? My understanding is that it should only be applied to js/mjs/cjs files if no files are specified.

Sorry, I noticed the PR was converted to draft but missed this question. Yes, it is expected behavior that config objects without files or ignores apply to all all files included in linting.

given extends has been shipped, I'll update the pr to use it. 🎉

👍 the problem mentioned in #151 (comment) looks like a good case for extends.

aladdin-add added a commit that referenced this pull request Mar 27, 2025
@github-project-automation github-project-automation bot moved this from Implementing to Complete in Triage Mar 27, 2025
nzakas pushed a commit that referenced this pull request Mar 31, 2025
* feat: support languages json/markdown

fixes #148

resubmit #151

* fix: extensions for typescript files

* refactor: language = js

* fix: global ignores

* fix: add css & use `extends`

* fix: vue + ts

* fix: review suggestions

* Update lib/config-generator.js

Co-authored-by: Milos Djermanovic <[email protected]>

* Update lib/config-generator.js

Co-authored-by: Milos Djermanovic <[email protected]>

* Update lib/config-generator.js

Co-authored-by: Milos Djermanovic <[email protected]>

* Update lib/config-generator.js

Co-authored-by: Milos Djermanovic <[email protected]>

* fix: review suggestions

* chore: update snapshots

* Update lib/config-generator.js

Co-authored-by: Milos Djermanovic <[email protected]>

* chore: update snapshots

* fix: review suggestions

* fix: opt config for markdown

---------

Co-authored-by: Milos Djermanovic <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Complete

Development

Successfully merging this pull request may close these issues.

Ask which languages to lint

4 participants