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

Add descriptions and examples to each lint rule #159

Closed
81 tasks done
bartlomieju opened this issue Jun 12, 2020 · 3 comments
Closed
81 tasks done

Add descriptions and examples to each lint rule #159

bartlomieju opened this issue Jun 12, 2020 · 3 comments
Labels
epic help wanted Extra attention is needed

Comments

@bartlomieju
Copy link
Member

bartlomieju commented Jun 12, 2020

All lint rules should be updated to contains some kind of method that returns description as well as some examples of valid and invalid. This feature will be used to generate documentation.

  • adjacent-overload-signatures
  • ban-ts-comment
  • ban-types
  • ban-untagged-ignore
  • ban-untagged-todo
  • constructor-super
  • default-param-last
  • eqeqeq
  • explicit-function-return-type
  • explicit-module-boundary-types
  • for-direction
  • getter-return
  • no-array-constructor
  • no-async-promise-executor
  • no-await-in-loop
  • no-case-declarations
  • no-class-assign
  • no-compare-neg-zero
  • no-cond-assign
  • no-const-assign
  • no-constant-condition
  • no-control-regex
  • no-debugger
  • no-delete-var
  • no-dupe-args
  • no-dupe-class-members
  • no-dupe-else-if
  • no-dupe-keys
  • no-duplicate-case
  • no-empty
  • no-empty-character-class
  • no-empty-interface
  • no-empty-pattern
  • no-eval
  • no-ex-assign
  • no-explicit-any
  • no-extra-boolean-cast
  • no-extra-non-null-assertion
  • no-extra-semi
  • no-fallthrough
  • no-func-assign
  • no-global-assign
  • no-import-assign
  • no-inferrable-types
  • no-inner-declarations
  • no-invalid-regexp
  • no-irregular-whitespace
  • no-misused-new
  • no-mixed-spaces-and-tabs
  • no-namespace
  • no-new-symbol
  • no-non-null-asserted-optional-chain
  • no-non-null-assertion
  • no-obj-calls
  • no-octal
  • no-prototype-builtins
  • no-redeclare
  • no-regex-spaces
  • no-self-assign
  • no-setter-return
  • no-shadow-restricted-names
  • no-sparse-arrays
  • no-this-alias
  • no-this-before-super
  • no-throw-literal
  • no-undef
  • no-unreachable
  • no-unsafe-finally
  • no-unsafe-negation
  • no-unused-labels
  • no-unused-vars
  • no-var
  • no-with
  • prefer-as-const
  • prefer-const
  • prefer-namespace-keyword
  • require-yield
  • single-var-declarator
  • triple-slash-reference
  • use-isnan
  • valid-typeof
@bartlomieju
Copy link
Member Author

bartlomieju commented Sep 29, 2020

I think it's high time to start adding rules documentation so I'm pinning this issue.

So to support basic documentation and website generation we need to change LintRule trait minimally:

pub trait LintRule {
  fn new() -> Box<Self>
  where
    Self: Sized;
  fn lint_module(
    &self,
    context: Arc<Context>,
    module: &swc_ecmascript::ast::Module,
  );
  fn code(&self) -> &'static str;
  fn docs(&self) -> &'static str; // <--- new method
}

LintRule::docs() would return a string with written documentation. I think it makes sense to support markdown being returned from this function because we could print it out nicely to terminal (for example using termimad) as well as auto-generate website similar to doc.deno.land.

Documentation for each lint rule should contain a short synopsis on what the rule does, why is it used and examples of both valid and invalid code.

Example for ban-untagged-todo:

Each "TODO" comment should be tagged with either a username or issue number.

Untagged TODOs often lead to confusion on the original intent of the TODO, 
especially after several git changes.

**Valid:**
// TODO(#101): need to handle edge case for n = 0
function foo(n: number) {
  // ...
}

**Invalid:**
// TODO: need to handle edge case for n = 0
function foo(n: number) {
  // ...
}

CC @lucacasonato

@bartlomieju bartlomieju added the help wanted Extra attention is needed label Sep 29, 2020
@bartlomieju bartlomieju pinned this issue Sep 29, 2020
@DomParfitt
Copy link
Contributor

DomParfitt commented Sep 29, 2020

I'm happy to look at implementing this on the rules I've implemented once the trait is updated. From a quick scan that covers:

  • no-empty
  • no-cond-assign
  • valid-typeof
  • no-unsafe-finally
  • no-compare-neg-zero
  • no-dupe-keys

🙂

@bartlomieju
Copy link
Member Author

@DomParfitt great, thank you! I've already merged #343

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
epic help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants