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

Change Request: docs: add example code for eslint.lintText #16666

Closed
1 task
milahu opened this issue Dec 15, 2022 · 3 comments · Fixed by #16789
Closed
1 task

Change Request: docs: add example code for eslint.lintText #16666

milahu opened this issue Dec 15, 2022 · 3 comments · Fixed by #16789
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion core Relates to ESLint's core APIs and features documentation Relates to ESLint's documentation enhancement This change enhances an existing feature of ESLint good first issue Good for people who haven't worked on ESLint before
Projects

Comments

@milahu
Copy link

milahu commented Dec 15, 2022

ESLint version

8.29.0

What problem do you want to solve?

no example code for eslint.lintText at

https://eslint.org/docs/latest/developer-guide/nodejs-api#eslint-class

What do you think is the correct solution?

add example code, something like

const { ESLint } = require("eslint");

let text = `
console.log("hello")
`

(async function main() {
  // 1. Create an instance with the `fix` option and some config.
  const eslint = new ESLint({
    fix: true,
    useEslintrc: false,
    overrideConfig: {
      "extends": [
        "eslint:recommended",
      ],
      "parserOptions": {
        "sourceType": "module",
        "ecmaVersion": "latest",
      },
      "env": {
        "es2022": true,
      },
    },
  });

  // 2. Lint text. Store fixed text in results[0].output.
  const results = await eslint.lintText(text, {filePath: "/script.js"});

  // 3. Format the messages.
  const formatter = await eslint.loadFormatter("stylish");
  const messages = formatter.format(results);

  // 4. Print the messages.
  console.log(messages);

  // 5 Print the new text.
  const newText = results[0].output;
  console.log(newText);
})().catch((error) => {
  process.exitCode = 1;
  console.error(error);
});

Participation

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

Additional comments

No response

@milahu milahu added core Relates to ESLint's core APIs and features enhancement This change enhances an existing feature of ESLint triage An ESLint team member will look at this issue soon labels Dec 15, 2022
@eslint-github-bot eslint-github-bot bot added this to Needs Triage in Triage Dec 15, 2022
@nzakas nzakas added documentation Relates to ESLint's documentation accepted There is consensus among the team that this change meets the criteria for inclusion good first issue Good for people who haven't worked on ESLint before and removed triage An ESLint team member will look at this issue soon labels Jan 3, 2023
@nzakas nzakas moved this from Needs Triage to Ready to Implement in Triage Jan 3, 2023
@nzakas
Copy link
Member

nzakas commented Jan 3, 2023

Sorry we missed this! We can definitely add an example there. Is that something you'd like to submit a pull request for?

@milahu
Copy link
Author

milahu commented Jan 4, 2023

Is that something you'd like to submit a pull request for?

nope, sorry

@siva-kannan3
Copy link
Contributor

@nzakas , I have created and tested a basic example. Here is the screenshot. Would love to give a PR for the same.

image

@nzakas nzakas linked a pull request Jan 20, 2023 that will close this issue
1 task
nzakas pushed a commit that referenced this issue Jan 20, 2023
Fixes #16666 

* docs: add example for nodejs lintText api

* Update docs/src/integrate/nodejs-api.md

Co-authored-by: 唯然 <weiran.zsd@outlook.com>

Co-authored-by: 唯然 <weiran.zsd@outlook.com>
@eslint-github-bot eslint-github-bot bot locked and limited conversation to collaborators Jul 20, 2023
@eslint-github-bot eslint-github-bot bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Jul 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion core Relates to ESLint's core APIs and features documentation Relates to ESLint's documentation enhancement This change enhances an existing feature of ESLint good first issue Good for people who haven't worked on ESLint before
Projects
Archived in project
Triage
Ready to Implement
Development

Successfully merging a pull request may close this issue.

3 participants