Skip to content

Commit

Permalink
chore(linter): write json schema to npm/oxlint
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed May 24, 2024
1 parent 5bf595d commit 9377a60
Show file tree
Hide file tree
Showing 8 changed files with 293 additions and 75 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.

3 changes: 2 additions & 1 deletion crates/oxc_linter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,5 @@ schemars = { workspace = true, features = ["indexmap2"] }
static_assertions = { workspace = true }

[dev-dependencies]
insta = { workspace = true }
insta = { workspace = true }
project-root = { workspace = true }
18 changes: 17 additions & 1 deletion crates/oxc_linter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,28 @@ impl Linter {

#[cfg(test)]
mod test {
use super::Linter;
use super::{Linter, OxlintConfig};

#[test]
fn print_rules() {
let mut writer = Vec::new();
Linter::print_rules(&mut writer);
assert!(!writer.is_empty());
}

#[test]
fn test_schema_json() {
use project_root::get_project_root;
use std::fs;
let path = get_project_root().unwrap().join("npm/oxlint/configuration_schema.json");
let schema = schemars::schema_for!(OxlintConfig);
let json = serde_json::to_string_pretty(&schema).unwrap();
let existing_json = fs::read_to_string(&path).unwrap_or_default();
if existing_json != json {
std::fs::write(&path, &json).unwrap();
}
insta::with_settings!({ prepend_module_to_snapshot => false }, {
insta::assert_snapshot!(json);
});
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: tasks/website/src/linter/json_schema.rs
expression: snapshot
source: crates/oxc_linter/src/lib.rs
expression: json
---
{
"$schema": "http://json-schema.org/draft-07/schema#",
Expand Down
66 changes: 3 additions & 63 deletions npm/oxlint/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,70 +42,10 @@ The Oxidation Compiler is creating a suite of high-performance tools for JavaScr

This is the linter for oxc.

See [usage instructions](https://oxc-project.github.io/docs/guide/usage/linter.html).

Run

* `npx --yes oxlint@latest` in your JavaScript / TypeScript codebase and see it complete in milliseconds. No configurations are required.
* `npx oxlint@latest --help` for usage instructions.
* `npx oxlint@latest --help` for quick usage instructions.
* `npx oxlint@latest --rules` for the list of rules.


### Usage Instructions

`npx oxlint@latest --help`:

```
Usage: oxlint [-A=NAME | -D=NAME]... [--fix] [-c=<./eslintrc.json>] [PATH]...
Allowing / Denying Multiple Lints
For example `-D correctness -A no-debugger` or `-A all -D no-debugger`.
The default category is "-D correctness".
Use "--rules" for rule names.
Use "--help --help" for rule categories.
-A, --allow=NAME Allow the rule or category (suppress the lint)
-D, --deny=NAME Deny the rule or category (emit an error)
Enable Plugins
--import-plugin Enable the experimental import plugin and detect ESM problems. It is
recommended to use along side with the `--tsconfig` option.
--jsdoc-plugin Enable the experimental jsdoc plugin and detect JSDoc problems
--jest-plugin Enable the Jest plugin and detect test problems
--jsx-a11y-plugin Enable the JSX-a11y plugin and detect accessibility problems
--nextjs-plugin Enable the Next.js plugin and detect Next.js problems
--react-perf-plugin Enable the React performance plugin and detect rendering performance
problems
Fix Problems
--fix Fix as many issues as possible. Only unfixed issues are reported in
the output
Ignore Files
--ignore-path=PATH Specify the file to use as your .eslintignore
--ignore-pattern=PAT Specify patterns of files to ignore (in addition to those in
.eslintignore)
--no-ignore Disables excluding of files from .eslintignore files, --ignore-path
flags and --ignore-pattern flags
Handle Warnings
--quiet Disable reporting on warnings, only errors are reported
--deny-warnings Ensure warnings produce a non-zero exit code
--max-warnings=INT 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 Use a specific output format (default, json, checkstyle, unix)
Miscellaneous
--threads=INT Number of threads to use. Set to 1 for using only 1 CPU core
Available positional items:
PATH Single file, single path or list of paths
Available options:
--rules list all the rules that are currently registered
-c, --config=<./eslintrc.json> ESLint configuration file (experimental)
--tsconfig=<./tsconfig.json> TypeScript `tsconfig.json` path for reading path alias and
project references for import plugin
-h, --help Prints help information
-V, --version Prints version information
```
267 changes: 267 additions & 0 deletions npm/oxlint/configuration_schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,267 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "OxlintConfig",
"description": "Oxlint Configuration File\n\nThis configuration is aligned with ESLint v8's configuration schema (`eslintrc.json`).\n\nUsage: `oxlint -c oxlintrc.json`\n\n::: danger NOTE\n\nOnly the `.json` format is supported.\n\n:::\n\nExample\n\n```json\n // oxlintrc.json\n {\n // Comments are supported.\n \"env\": {\n \"browser\": true\n },\n \"globals\": {\n \"foo\": \"readonly\",\n },\n \"settings\": {\n },\n \"rules\": {\n \"eqeqeq\": \"warn\",\n },\n }\n```",
"type": "object",
"properties": {
"env": {
"$ref": "#/definitions/OxlintEnv"
},
"globals": {
"$ref": "#/definitions/OxlintGlobals"
},
"rules": {
"description": "See [Oxlint Rules](./rules)",
"allOf": [
{
"$ref": "#/definitions/OxlintRules"
}
]
},
"settings": {
"$ref": "#/definitions/OxlintSettings"
}
},
"definitions": {
"CustomComponent": {
"anyOf": [
{
"type": "string"
},
{
"type": "object",
"required": [
"attribute",
"name"
],
"properties": {
"attribute": {
"type": "string"
},
"name": {
"type": "string"
}
}
},
{
"type": "object",
"required": [
"attributes",
"name"
],
"properties": {
"attributes": {
"type": "array",
"items": {
"type": "string"
}
},
"name": {
"type": "string"
}
}
}
]
},
"DummyRule": {
"anyOf": [
{
"type": "integer",
"format": "uint",
"minimum": 0.0
},
{
"type": "string"
},
{
"type": "array",
"items": true
}
]
},
"GlobalValue": {
"type": "string",
"enum": [
"readonly",
"writeable",
"off"
]
},
"JSDocPluginSettings": {
"type": "object",
"properties": {
"augmentsExtendsReplacesDocs": {
"description": "Only for `require-(yields|returns|description|example|param|throws)` rule",
"default": false,
"type": "boolean"
},
"exemptDestructuredRootsFromChecks": {
"description": "Only for `require-param-type` and `require-param-description` rule",
"default": false,
"type": "boolean"
},
"ignoreInternal": {
"description": "For all rules but NOT apply to `empty-tags` rule",
"default": false,
"type": "boolean"
},
"ignorePrivate": {
"description": "For all rules but NOT apply to `check-access` and `empty-tags` rule",
"default": false,
"type": "boolean"
},
"ignoreReplacesDocs": {
"description": "Only for `require-(yields|returns|description|example|param|throws)` rule",
"default": true,
"type": "boolean"
},
"implementsReplacesDocs": {
"description": "Only for `require-(yields|returns|description|example|param|throws)` rule",
"default": false,
"type": "boolean"
},
"overrideReplacesDocs": {
"description": "Only for `require-(yields|returns|description|example|param|throws)` rule",
"default": true,
"type": "boolean"
},
"tagNamePreference": {
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/TagNamePreference"
}
}
}
},
"JSXA11yPluginSettings": {
"type": "object",
"properties": {
"components": {
"default": {},
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"polymorphicPropName": {
"type": [
"string",
"null"
]
}
}
},
"NextPluginSettings": {
"type": "object",
"properties": {
"rootDir": {
"$ref": "#/definitions/OneOrMany_for_String"
}
}
},
"OneOrMany_for_String": {
"anyOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "string"
}
}
]
},
"OxlintEnv": {
"description": "Predefine global variables.",
"type": "object",
"additionalProperties": {
"type": "boolean"
}
},
"OxlintGlobals": {
"description": "Add or remove global variables.",
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/GlobalValue"
}
},
"OxlintRules": {
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/DummyRule"
}
},
"OxlintSettings": {
"description": "Shared settings for plugins",
"type": "object",
"properties": {
"jsdoc": {
"$ref": "#/definitions/JSDocPluginSettings"
},
"jsx-a11y": {
"$ref": "#/definitions/JSXA11yPluginSettings"
},
"next": {
"$ref": "#/definitions/NextPluginSettings"
},
"react": {
"$ref": "#/definitions/ReactPluginSettings"
}
}
},
"ReactPluginSettings": {
"type": "object",
"properties": {
"formComponents": {
"type": "array",
"items": {
"$ref": "#/definitions/CustomComponent"
}
},
"linkComponents": {
"type": "array",
"items": {
"$ref": "#/definitions/CustomComponent"
}
}
}
},
"TagNamePreference": {
"anyOf": [
{
"type": "string"
},
{
"type": "object",
"required": [
"message",
"replacement"
],
"properties": {
"message": {
"type": "string"
},
"replacement": {
"type": "string"
}
}
},
{
"type": "object",
"required": [
"message"
],
"properties": {
"message": {
"type": "string"
}
}
},
{
"type": "boolean"
}
]
}
}
}
Loading

0 comments on commit 9377a60

Please sign in to comment.