Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,8 @@ cd eipw-lint-js
wasm-pack test --node
wasm-pack build -t nodejs
wasm-pack publish -t nodejs
# for type test
cd type-checks
npm install
npm run test
```
136 changes: 134 additions & 2 deletions eipw-lint-js/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,138 @@ use std::pin::Pin;

use wasm_bindgen::prelude::*;

#[wasm_bindgen(typescript_custom_section)]
const TS_APPEND_CONTENT: &'static str = r#"
export type Author<S> = S;

export type Date<S> = S;

export type DefaultLint<S> =
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you think of a way we can get a compile or test failure if this list gets out of sync with DefaultLint?

| {kind: "preamble-author"; name: Author<S>}
| {kind: "preamble-date"; name: Date<S>}
| ({kind: "preamble-file-name"} & FileName<S>)
| ({kind: "preamble-length"} & Length<S>)
| {kind: "preamble-list"; name: List<S>}
| ({kind: "preamble-no-duplicates"} & NoDuplicates)
| ({kind: "preamble-one-of"} & OneOf<S>)
| {kind: "preamble-order"; names: Order<S>}
| ({kind: "preamble-proposal-ref"} & ProposalRef<S>)
| ({kind: "preamble-regex"} & Regex<S>)
| ({kind: "preamble-require-referenced"} & RequireReferenced<S>)
| {kind: "preamble-required"; names: Required<S>}
| ({kind: "preamble-required-if-eq"} & RequiredIfEq<S>)
| ({kind: "preamble-requires-status"} & RequiresStatus<S>)
| ({kind: "preamble-trim"} & Trim)
| {kind: "preamble-uint"; name: Uint<S>}
| {kind: "preamble-uint-list"; name: UintList<S>}
| {kind: "preamble-url"; name: Url<S>}
| ({kind: "markdown-html-comments"} & HtmlComments<S>)
| ({kind: "markdown-json-schema"} & JsonSchema<S>)
| {kind: "markdown-link-first"; pattern: LinkFirst<S>}
| ({kind: "markdown-link-status"} & LinkStatus<S>)
| ({kind: "markdown-proposal-ref"} & ProposalRef<S>)
| ({kind: "markdown-regex"} & Regex<S>)
| ({kind: "markdown-relative-links"} & RelativeLinks<S>)
| {kind: "markdown-section-order"; sections: SectionOrder<S>}
| {kind: "markdown-section-required"; sections: SectionRequired<S>}
| ({kind: "markdown-headings-space"} & HeadingsSpace);

export type DefaultModifier<S> = {
kind: "set-default-annotation";
} & SetDefaultAnnotation<S>;

export type FileName<S> = {name: S; prefix: S; suffix: S};

export type HeadingsSpace = null;

export type HtmlComments<S> = {name: S; warn_for: Array<S>};

export type JsonSchema<S> = {
language: S;
additional_schemas: Array<[S, S]>;
schema: S;
help: S;
};

export type Length<S> = {name: S; min: number | null; max: number | null};

export type LinkFirst<S> = S;

export type LinkStatus<S> = {
status: S;
flow: Array<Array<S>>;
prefix: S;
suffix: S;
};

export type List<S> = S;

export type Mode = "includes" | "excludes";

export type NoDuplicates = null;

export type OneOf<S> = {name: S; values: Array<S>};

export type Opts = {
allow?: Array<string>;
warn?: Array<string>;
deny?: Array<string>;
default_lints?: {[key: string]: DefaultLint<string>} | null;
default_modifiers?: Array<DefaultModifier<string>> | null;
};

export type Order<S> = Array<S>;

export type ProposalRef<S> = {name: S; prefix: S; suffix: S};

export type Regex<S> = {name: S; mode: Mode; pattern: S; message: S};

export type RelativeLinks<S> = {exceptions: Array<S>};

export type RequireReferenced<S> = {name: S; requires: S};

export type Required<S> = Array<S>;

export type RequiredIfEq<S> = {when: S; equals: S; then: S};

export type RequiresStatus<S> = {
requires: S;
status: S;
flow: Array<Array<S>>;
prefix: S;
suffix: S;
};

export type SectionOrder<S> = Array<S>;

export type SectionRequired<S> = Array<S>;

type AnnotationTypeDef = "error" | "warning" | "info" | "note" | "help";

export type SetDefaultAnnotation<S> = {
name: S;
value: S;
annotation_type: AnnotationTypeDef;
};

export type Trim = null;

export type Uint<S> = S;

export type UintList<S> = S;

export type Url<S> = S;

export type SnippetDef = {
formatted: string;
[key: string]: any;
};

export function lint(sources: string[], options?: Opts): Promise<SnippetDef[]>;

export function format(snippet: SnippetDef): string;
"#;

#[derive(Debug)]
struct Error(String);

Expand Down Expand Up @@ -112,7 +244,7 @@ impl Opts {
}
}

#[wasm_bindgen]
#[wasm_bindgen(skip_typescript)]
pub async fn lint(sources: Vec<JsValue>, options: Option<Object>) -> Result<JsValue, JsError> {
let sources: Vec<_> = sources
.into_iter()
Expand Down Expand Up @@ -172,7 +304,7 @@ pub async fn lint(sources: Vec<JsValue>, options: Option<Object>) -> Result<JsVa
Ok(js_value)
}

#[wasm_bindgen]
#[wasm_bindgen(skip_typescript)]
pub fn format(snippet: &JsValue) -> Result<String, JsError> {
let value: serde_json::Value = serde_wasm_bindgen::from_value(snippet.clone())?;

Expand Down
3 changes: 3 additions & 0 deletions eipw-lint-js/type-checks/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/*
package-lock.json
pnpm-lock.yaml
8 changes: 8 additions & 0 deletions eipw-lint-js/type-checks/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
preset: "ts-jest",
testEnvironment: "node",
roots: ["<rootDir>/tests"],
// transform: {
// ...createDefaultPreset().transform,
// },
};
21 changes: 21 additions & 0 deletions eipw-lint-js/type-checks/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "type-checks",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "npx jest"
},
"keywords": [],
"author": "",
"license": "ISC",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should be MPL-2.0 to match the rest of the project.

"devDependencies": {
"@types/jest": "^29.5.12",
"jest": "^29.7.0",
"ts-jest": "^29.2.4",
"typescript": "^5.5.4"
},
"dependencies": {
"ts-node": "^10.9.2"
}
}
40 changes: 40 additions & 0 deletions eipw-lint-js/type-checks/tests/eips/eip-1000.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
eip: 1000
title: A sample proposal
description: This proposal is a sample that should be considered
author: John Doe (@johndoe), Jenny Doe <jenny.doe@example.com>
discussions-to: https://ethereum-magicians.org/t/foo/1
status: Last Call
last-call-deadline: 2020-01-01
type: Standards Track
category: Core
created: 2020-01-01
requires: 20
---

## Abstract
This is the abstract for the EIP.

## Motivation
This is the motivation for the EIP.

## Specification
This is the specification for the EIP.

## Rationale
This is the rationale for the EIP.

## Backwards Compatibility
These are the backwards compatibility concerns for the EIP.

## Test Cases
These are the test cases for the EIP.

## Reference Implementation
This is the implementation for the EIP.

## Security Considerations
These are the security considerations for the EIP.

## Copyright
Copyright and related rights waived via [CC0](../LICENSE.md).
4 changes: 4 additions & 0 deletions eipw-lint-js/type-checks/tests/eips/eip-20.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
status: Draft
---

48 changes: 48 additions & 0 deletions eipw-lint-js/type-checks/tests/eips/eip-2000.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
eip: 2000
title: A sample proposal
description: This proposal is a sample that should be considered
author: John Doe (@johndoe), Jenny Doe <jenny.doe@example.com>
discussions-to: https://ethereum-magicians.org/t/hello/1
status: Last Call
last-call-deadline: 2020-01-01
type: Standards Track
category: Core
created: 2020-01-01
---

## Abstract
This is the abstract for the EIP.[^1]

## Motivation
This is the motivation for the EIP.

## Specification
This is the specification for the EIP.

## Rationale
This is the rationale for the EIP.

## Backwards Compatibility
These are the backwards compatibility concerns for the EIP.

## Test Cases
These are the test cases for the EIP.

## Reference Implementation
This is the implementation for the EIP.

## Security Considerations
These are the security considerations for the EIP.

## Copyright
Copyright and related rights waived via [CC0](../LICENSE.md).

[^1]:
```csl-json
{
"type": "article",
"id": "1",
"URL": "3"
}
```
Loading