Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support languages json/markdown #151

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft

feat: support languages json/markdown #151

wants to merge 10 commits into from

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
lib/questions.js Outdated Show resolved Hide resolved
@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"]
}

bin/create-config.js Outdated Show resolved Hide resolved
Co-authored-by: Milos Djermanovic <[email protected]>
@@ -12,6 +12,7 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug

/** @type {import('eslint').Linter.Config[]} */
export default [
{ignores: ["**/*.js", "**/*.cjs", "**/*.mjs"]},
Copy link
Member

Choose a reason for hiding this comment

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

Tests should be updated to pass languages: ["javascript"]?

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

Copy link
Member Author

Choose a reason for hiding this comment

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

lib/questions.js Outdated Show resolved Hide resolved
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},
];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Implementing
Development

Successfully merging this pull request may close these issues.

Ask which languages to lint
3 participants