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

Want to use oxc_linter as crate #7509

Closed
ityuany opened this issue Nov 27, 2024 · 15 comments
Closed

Want to use oxc_linter as crate #7509

ityuany opened this issue Nov 27, 2024 · 15 comments
Labels
C-enhancement Category - New feature or request

Comments

@ityuany
Copy link

ityuany commented Nov 27, 2024

I really like the oxc series of tools.

We have a scenario where oxc_linter is intended to be used directly as rust crate. Could you please send a package to support it

@ityuany ityuany added the C-enhancement Category - New feature or request label Nov 27, 2024
@Boshen
Copy link
Member

Boshen commented Nov 27, 2024

That's extended maintenance burden for us. Can you use git = "https://github.com/oxc-project/oxc.git" first and send PRs to make it accessible before we release it crates.io?

@ityuany
Copy link
Author

ityuany commented Nov 27, 2024

@Boshen

This will cause me to download an additional napi, once

image

@Boshen
Copy link
Member

Boshen commented Nov 27, 2024

@Boshen

This will cause me to download an additional napi, once

image

I removed it in #7510, but version will still conflict ...

@Boshen Boshen closed this as not planned Won't fix, can't repro, duplicate, stale Nov 27, 2024
@ityuany
Copy link
Author

ityuany commented Nov 28, 2024

image

Does this seem to have new requirements for my rust version?

@ityuany
Copy link
Author

ityuany commented Nov 28, 2024

@Boshen

Sorry, I'm a rust novice and used to work more on node and the front end. I don't quite understand why releasing oxc to Crate.io would add an extra maintenance burden, my understanding he should just be more than a publish action, perhaps I exist in the knowledge of the blind, can answer it. In addition, it may be important to me that OXC be released to Crate.io so I can use it directly, and I'd still like to support it if possible. Thank you very much

@nrayburn-tech
Copy link
Contributor

Releasing as a crate means that it now needs to be maintained and supported for clients to use. This includes things like APIs that make sense for clients (structs, methods), changelog, etc. This maintenance is the extra burden. The action of just publishing it is unlikely to be an issue.

@camc314
Copy link
Contributor

camc314 commented Nov 30, 2024

image Does this seem to have new requirements for my rust version?

Looks like this was stablized in 1.81.0 . i would try updating your rust version to solve the problem

rust-lang/rust#120924

@ityuany
Copy link
Author

ityuany commented Nov 30, 2024

Releasing as a crate means that it now needs to be maintained and supported for clients to use. This includes things like APIs that make sense for clients (structs, methods), changelog, etc. This maintenance is the extra burden. The action of just publishing it is unlikely to be an issue.

I understand, I think what you said makes a lot of sense, thank you for your response. Maybe I should try to understand the overall code design of oxc more deeply, and then try to take on this part of the work actively?

@nrayburn-tech
Copy link
Contributor

nrayburn-tech commented Nov 30, 2024

I believe that is what Boshen was suggesting. My understanding of it is below, although you should confirm with him.

Use the library with the GitHub URL for now. As you find issues, submit PRs to make improvements. Once things have been improved in a way that it is better to consume as a library and Boshen is comfortable with it not adding a significant maintenance burden, publishing as a crate becomes a much more realistic option (publishing as a crate isn’t guaranteed at this point, but it also isn’t completely off the table).

@ityuany
Copy link
Author

ityuany commented Dec 11, 2024

I tried to install it using the git address and found the private module

image image

@Boshen
Copy link
Member

Boshen commented Dec 11, 2024

I tried to install it using the git address and found the private module

image image

Can you PR?

@ityuany
Copy link
Author

ityuany commented Dec 11, 2024

I think maybe I found the right way to use it, but there seems to be some compatibility issues。

Excuse me, I am a novice, I don't know how to fix it.

image
use std::{path::Path, rc::Rc, sync::Arc};

use oxc_allocator::Allocator;
use oxc_linter::{
  AllowWarnDeny, FixKind, LintFilter, LintFilterKind, LinterBuilder,
  RuleCategory,
};
use oxc_parser::Parser;
use oxc_semantic::SemanticBuilder;
use oxc_span::SourceType;

fn main() -> std::io::Result<()> {
  let path = Path::new("hello.js");
  let source_text = std::fs::read_to_string(path)?;

  let allocator = Allocator::default();
  let source_type = SourceType::from_path(path).unwrap();
  let ret = Parser::new(&allocator, &source_text, source_type).parse();

  let semantic_builder = SemanticBuilder::new()
    .with_cfg(true)
    .with_scope_tree_child_ids(true);

  let semantic_ret = semantic_builder.build(&ret.program);
  let semantic = Rc::new(semantic_ret.semantic);
  let module_record = Arc::new(oxc_linter::ModuleRecord::new(
    path,
    &ret.module_record,
    semantic,
  ));

  let linter = LinterBuilder::default()
    .with_filters(vec![
      LintFilter::new(AllowWarnDeny::Warn, "no-debugger").unwrap(),
      LintFilter::new(AllowWarnDeny::Deny, "no-console").unwrap(),
      LintFilter::new(AllowWarnDeny::Warn, "no-commonjs").unwrap(),
      LintFilter::new(AllowWarnDeny::Warn, RuleCategory::Correctness).unwrap(),
    ])
    .with_fix(FixKind::None)
    .build();

  let diagnostics = linter.run(path, semantic, module_record);

  for message in diagnostics {
    println!("{:?}", message.error);
  }

  Ok(())
}
image

@ityuany
Copy link
Author

ityuany commented Dec 11, 2024

image

image

@Boshen
Copy link
Member

Boshen commented Dec 11, 2024

@ityuany use 0.39.0 for now, there's a problem with 0.40.1.

And this is why I don't want to release it as a crate, this process is already burdening.

@ityuany
Copy link
Author

ityuany commented Dec 12, 2024

image

I've found that this works fine, but it creates a confusion for my team members that all tags use oxlint_v0.15.0, which makes the versions of oxc_ast, oxc_span, ... This will make the versions of oxc_ast, oxc_span, ... less intuitive and clear. But at least this way he is working. I'm going to use it this way for now, and wait for the next dear Boshen to solve the conflict problem better!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category - New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants