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

feat(linter): Implement jsdoc/check-access #2642

Merged
merged 17 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Follow main updates
  • Loading branch information
leaysgur committed Mar 28, 2024
commit f3c432263cdff27c099e5789eb671f6c0410ffe4
13 changes: 5 additions & 8 deletions crates/oxc_linter/src/rules/jsdoc/check_access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ const ACCESS_LEVELS: phf::Set<&'static str> = phf_set! {
};

// TODO: Diagnostic message
// TODO: Diagnostic span, how to get it?

impl Rule for CheckAccess {
fn run_once(&self, ctx: &LintContext) {
Expand All @@ -54,21 +53,19 @@ impl Rule for CheckAccess {

for jsdoc in ctx.semantic().jsdoc().iter_all() {
let mut access_related_tags_count = 0;
for tag in jsdoc.tags() {
let tag_name = tag.tag_name();

if access_related_tag_names.contains(tag_name) {
for (span, tag) in jsdoc.tags() {
if access_related_tag_names.contains(tag.kind) {
access_related_tags_count += 1;
}

// Has valid access level?
if tag_name == resolved_access_tag_name && !ACCESS_LEVELS.contains(&tag.comment) {
ctx.diagnostic(CheckAccessDiagnostic(Span::default()));
if tag.kind == resolved_access_tag_name && !ACCESS_LEVELS.contains(&tag.comment()) {
ctx.diagnostic(CheckAccessDiagnostic(*span));
}

// Has redundant access level?
if 1 < access_related_tags_count {
ctx.diagnostic(CheckAccessDiagnostic(Span::default()));
ctx.diagnostic(CheckAccessDiagnostic(*span));
}
}
}
Expand Down
80 changes: 40 additions & 40 deletions crates/oxc_linter/src/snapshots/check_access.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,100 +3,100 @@ source: crates/oxc_linter/src/tester.rs
expression: check_access
---
⚠ eslint-plugin-jsdoc(check-access): TODO
╭─[check_access.tsx:1:1]
1 │
· ▲
╭─[check_access.tsx:3:17]
2 │ /**
3 │ * @access foo
· ───────
4 │ */
╰────
help: TODO

⚠ eslint-plugin-jsdoc(check-access): TODO
╭─[check_access.tsx:1:1]
1 │
· ▲
╭─[check_access.tsx:3:17]
2 │ /**
3 │ * @access foo
· ───────
4 │ */
╰────
help: TODO

⚠ eslint-plugin-jsdoc(check-access): TODO
╭─[check_access.tsx:1:1]
1 │
· ▲
╭─[check_access.tsx:3:25]
2 │ /**
3 │ * @accessLevel foo
· ────────────
4 │ */
╰────
help: TODO

⚠ eslint-plugin-jsdoc(check-access): TODO
╭─[check_access.tsx:1:1]
1 │
· ▲
╭─[check_access.tsx:3:17]
2 │ /**
3 │ * @access
· ───────
4 │ */
╰────
help: TODO

⚠ eslint-plugin-jsdoc(check-access): TODO
╭─[check_access.tsx:1:1]
1 │
· ▲
2 │ class MyClass {
╭─[check_access.tsx:4:15]
3 │ /**
4 │ * @access
· ───────
5 │ */
╰────
help: TODO

⚠ eslint-plugin-jsdoc(check-access): TODO
╭─[check_access.tsx:1:1]
1 │
· ▲
2 │ /**
╭─[check_access.tsx:4:17]
3 │ * @access public
4 │ * @public
· ───────
5 │ */
╰────
help: TODO

⚠ eslint-plugin-jsdoc(check-access): TODO
╭─[check_access.tsx:1:1]
1 │
· ▲
2 │ /**
╭─[check_access.tsx:4:17]
3 │ * @access public
4 │ * @access private
· ───────
5 │ */
╰────
help: TODO

⚠ eslint-plugin-jsdoc(check-access): TODO
╭─[check_access.tsx:1:1]
1 │
· ▲
2 │ /**
╭─[check_access.tsx:4:17]
3 │ * @access public
4 │ * @access private
· ───────
5 │ */
╰────
help: TODO

⚠ eslint-plugin-jsdoc(check-access): TODO
╭─[check_access.tsx:1:1]
1 │
· ▲
2 │ /**
╭─[check_access.tsx:4:17]
3 │ * @public
4 │ * @private
· ────────
5 │ */
╰────
help: TODO

⚠ eslint-plugin-jsdoc(check-access): TODO
╭─[check_access.tsx:1:1]
1 │
· ▲
2 │ /**
╭─[check_access.tsx:4:17]
3 │ * @public
4 │ * @private
· ────────
5 │ */
╰────
help: TODO

⚠ eslint-plugin-jsdoc(check-access): TODO
╭─[check_access.tsx:1:1]
1 │
· ▲
2 │ /**
╭─[check_access.tsx:4:17]
3 │ * @public
4 │ * @public
· ───────
5 │ */
╰────
help: TODO
Loading