Skip to content

Commit

Permalink
chore(website): snapshot cli and json schema output
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed May 24, 2024
1 parent ecdffcf commit 809e4fc
Show file tree
Hide file tree
Showing 10 changed files with 669 additions and 16 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions tasks/website/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ workspace = true
name = "website"
test = false

[lib]
doctest = false

[dependencies]
oxc_linter = { workspace = true }
oxc_cli = { path = "../../crates/oxc_cli" }
Expand All @@ -22,3 +25,6 @@ serde_json = { workspace = true }
schemars = { workspace = true }
handlebars = { workspace = true }
serde = { workspace = true }

[dev-dependencies]
insta = { workspace = true }
18 changes: 15 additions & 3 deletions tasks/website/src/linter/cli.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
use bpaf::Parser;
use oxc_cli::lint_options;

#[test]
fn test_cli() {
let snapshot = generate_cli();
insta::with_settings!({ prepend_module_to_snapshot => false }, {
insta::assert_snapshot!(snapshot);
});
}

// <https://oxc-project.github.io/docs/guide/usage/linter/cli.html>
pub fn generate_cli() {
pub fn print_cli() {
println!("{}", generate_cli());
}

fn generate_cli() -> String {
let markdown = lint_options().to_options().render_markdown("oxlint");
// Remove the extra header
let markdown = markdown.trim_start_matches("# oxlint\n");
Expand Down Expand Up @@ -32,13 +44,13 @@ pub fn generate_cli() {
})
.collect::<Vec<_>>()
.join("\n");
println!(
format!(
"
<!-- textlint-disable -->
{markdown}
<!-- textlint-enable -->
"
);
)
}
33 changes: 28 additions & 5 deletions tasks/website/src/linter/json_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,38 @@ use serde::Serialize;

use oxc_linter::ESLintConfig;

pub fn generate_schema_json() {
#[test]
fn test_schema_json() {
let snapshot = generate_schema_json();
insta::with_settings!({ prepend_module_to_snapshot => false }, {
insta::assert_snapshot!(snapshot);
});
}

pub fn print_schema_json() {
println!("{}", generate_schema_json());
}

fn generate_schema_json() -> String {
let schema = schema_for!(ESLintConfig);
println!("{}", serde_json::to_string_pretty(&schema).unwrap());
serde_json::to_string_pretty(&schema).unwrap()
}

#[test]
fn test_schema_markdown() {
let snapshot = generate_schema_markdown();
insta::with_settings!({ prepend_module_to_snapshot => false }, {
insta::assert_snapshot!(snapshot);
});
}

pub fn print_schema_markdown() {
println!("{}", generate_schema_markdown());
}

pub fn generate_schema_markdown() {
fn generate_schema_markdown() -> String {
let root_schema = schema_for!(ESLintConfig);
let rendered = Renderer::new(root_schema).render();
println!("{rendered}");
Renderer::new(root_schema).render()
}

const ROOT: &str = "
Expand Down
6 changes: 3 additions & 3 deletions tasks/website/src/linter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod json_schema;
mod rules;

pub use self::{
cli::generate_cli,
json_schema::{generate_schema_json, generate_schema_markdown},
rules::generate_rules,
cli::print_cli,
json_schema::{print_schema_json, print_schema_markdown},
rules::print_rules,
};
2 changes: 1 addition & 1 deletion tasks/website/src/linter/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use oxc_linter::table::RuleTable;

// `cargo run -p website linter-rules > /path/to/oxc/oxc-project.github.io/src/docs/guide/usage/linter/generated-rules.md`
// <https://oxc-project.github.io/docs/guide/usage/linter/rules.html>
pub fn generate_rules() {
pub fn print_rules() {
let table = RuleTable::new();

let total = table.total;
Expand Down
129 changes: 129 additions & 0 deletions tasks/website/src/linter/snapshots/cli.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
---
source: tasks/website/src/linter/cli.rs
expression: snapshot
---
<!-- textlint-disable -->


## Usage
**`oxlint`** \[**`-c`**=_`<./eslintrc.json>`_\] \[**`--fix`**\] \[_`PATH`_\]...

## Basic Configuration
- **`-c`**, **`--config`**=_`<./eslintrc.json>`_ &mdash;
ESLint configuration file (experimental)

* only `.json` extension is supported
- **` --tsconfig`**=_`<./tsconfig.json>`_ &mdash;
TypeScript `tsconfig.json` path for reading path alias and project references for import plugin



## Allowing / Denying Multiple Lints
Accumulate rules and categories from left to right on the command-line.


For example `-D correctness -A no-debugger` or `-A all -D no-debugger`.
The categories are:
* `correctness` - code that is outright wrong or useless (default)
* `suspicious` - code that is most likely wrong or useless
* `pedantic` - lints which are rather strict or have occasional false positives
* `style` - code that should be written in a more idiomatic way
* `nursery` - new lints that are still under development
* `restriction` - lints which prevent the use of language and library features
* `all` - all the categories listed above except nursery

Arguments:

- **`-A`**, **`--allow`**=_`NAME`_ &mdash;
Allow the rule or category (suppress the lint)
- **`-W`**, **`--warn`**=_`NAME`_ &mdash;
Deny the rule or category (emit a warning)
- **`-D`**, **`--deny`**=_`NAME`_ &mdash;
Deny the rule or category (emit an error)



## Enable Plugins
- **` --disable-react-plugin`** &mdash;
Disable react plugin, which is turned on by default
- **` --disable-unicorn-plugin`** &mdash;
Disable unicorn plugin, which is turned on by default
- **` --disable-oxc-plugin`** &mdash;
Disable oxc unique rules, which is turned on by default
- **` --disable-typescript-plugin`** &mdash;
Disable TypeScript plugin, which is turned on by default
- **` --import-plugin`** &mdash;
Enable the experimental import plugin and detect ESM problems. It is recommended to use along side with the `--tsconfig` option.
- **` --jsdoc-plugin`** &mdash;
Enable the experimental jsdoc plugin and detect JSDoc problems
- **` --jest-plugin`** &mdash;
Enable the Jest plugin and detect test problems
- **` --jsx-a11y-plugin`** &mdash;
Enable the JSX-a11y plugin and detect accessibility problems
- **` --nextjs-plugin`** &mdash;
Enable the Next.js plugin and detect Next.js problems
- **` --react-perf-plugin`** &mdash;
Enable the React performance plugin and detect rendering performance problems



## Fix Problems
- **` --fix`** &mdash;
Fix as many issues as possible. Only unfixed issues are reported in the output



## Ignore Files
- **` --ignore-path`**=_`PATH`_ &mdash;
Specify the file to use as your .eslintignore
- **` --ignore-pattern`**=_`PAT`_ &mdash;
Specify patterns of files to ignore (in addition to those in .eslintignore)

The supported syntax is the same as for .eslintignore and .gitignore files You should quote your patterns in order to avoid shell interpretation of glob patterns
- **` --no-ignore`** &mdash;
Disables excluding of files from .eslintignore files, **`--ignore-path`** flags and **`--ignore-pattern`** flags
- **` --symlinks`** &mdash;
Follow symbolic links. Oxlint ignores symbolic links by default.



## Handle Warnings
- **` --quiet`** &mdash;
Disable reporting on warnings, only errors are reported
- **` --deny-warnings`** &mdash;
Ensure warnings produce a non-zero exit code
- **` --max-warnings`**=_`INT`_ &mdash;
Specify a warning threshold, which can be used to force exit with an error status if there are too many warning-level rule violations in your project



## Output
- **`-f`**, **`--format`**=_`ARG`_ &mdash;
Use a specific output format (default, json, unix, checkstyle, github)



## Miscellaneous
- **` --silent`** &mdash;
Do not display any diagnostics
- **` --threads`**=_`INT`_ &mdash;
Number of threads to use. Set to 1 for using only 1 CPU core



## Available positional items:
- _`PATH`_ &mdash;
Single file, single path or list of paths



## Available options:
- **` --rules`** &mdash;
list all the rules that are currently registered
- **`-h`**, **`--help`** &mdash;
Prints help information




<!-- textlint-enable -->
Loading

0 comments on commit 809e4fc

Please sign in to comment.