1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
// Copyright 2020 the Deno authors. All rights reserved. MIT license.
use crate::linter::Context;
use std::sync::Arc;

pub mod adjacent_overload_signatures;
pub mod ban_ts_comment;
pub mod ban_ts_ignore;
pub mod ban_types;
pub mod ban_untagged_ignore;
pub mod ban_untagged_todo;
pub mod constructor_super;
pub mod default_param_last;
pub mod eqeqeq;
pub mod explicit_function_return_type;
pub mod explicit_module_boundary_types;
pub mod for_direction;
pub mod getter_return;
pub mod no_array_constructor;
pub mod no_async_promise_executor;
pub mod no_await_in_loop;
pub mod no_case_declarations;
pub mod no_class_assign;
pub mod no_compare_neg_zero;
pub mod no_cond_assign;
pub mod no_const_assign;
pub mod no_constant_condition;
pub mod no_control_regex;
pub mod no_debugger;
pub mod no_delete_var;
pub mod no_dupe_args;
pub mod no_dupe_class_members;
pub mod no_dupe_else_if;
pub mod no_dupe_keys;
pub mod no_duplicate_case;
pub mod no_empty;
pub mod no_empty_character_class;
pub mod no_empty_interface;
pub mod no_empty_pattern;
pub mod no_eval;
pub mod no_ex_assign;
pub mod no_explicit_any;
pub mod no_extra_boolean_cast;
pub mod no_extra_non_null_assertion;
pub mod no_extra_semi;
pub mod no_func_assign;
pub mod no_inferrable_types;
pub mod no_invalid_regexp;
pub mod no_irregular_whitespace;
pub mod no_misused_new;
pub mod no_mixed_spaces_and_tabs;
pub mod no_namespace;
pub mod no_new_symbol;
pub mod no_non_null_asserted_optional_chain;
pub mod no_non_null_assertion;
pub mod no_obj_calls;
pub mod no_octal;
pub mod no_prototype_builtins;
pub mod no_regex_spaces;
pub mod no_self_assign;
pub mod no_setter_return;
pub mod no_shadow_restricted_names;
pub mod no_sparse_array;
pub mod no_this_alias;
pub mod no_this_before_super;
pub mod no_throw_literal;
pub mod no_unexpected_multiline;
pub mod no_unsafe_finally;
pub mod no_unsafe_negation;
pub mod no_unused_labels;
pub mod no_unused_vars;
pub mod no_var;
pub mod no_with;
pub mod prefer_as_const;
pub mod prefer_namespace_keyword;
pub mod require_yield;
pub mod single_var_declarator;
pub mod triple_slash_reference;
pub mod use_isnan;
pub mod valid_typeof;

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;
}

pub fn get_recommended_rules() -> Vec<Box<dyn LintRule>> {
  vec![
    adjacent_overload_signatures::AdjacentOverloadSignatures::new(),
    ban_ts_comment::BanTsComment::new(),
    ban_untagged_ignore::BanUntaggedIgnore::new(),
    ban_types::BanTypes::new(),
    constructor_super::ConstructorSuper::new(),
    for_direction::ForDirection::new(),
    getter_return::GetterReturn::new(),
    no_array_constructor::NoArrayConstructor::new(),
    no_async_promise_executor::NoAsyncPromiseExecutor::new(),
    no_case_declarations::NoCaseDeclarations::new(),
    no_class_assign::NoClassAssign::new(),
    no_compare_neg_zero::NoCompareNegZero::new(),
    no_cond_assign::NoCondAssign::new(),
    no_control_regex::NoControlRegex::new(),
    no_debugger::NoDebugger::new(),
    no_delete_var::NoDeleteVar::new(),
    no_dupe_args::NoDupeArgs::new(),
    no_dupe_class_members::NoDupeClassMembers::new(),
    no_dupe_else_if::NoDupeElseIf::new(),
    no_dupe_keys::NoDupeKeys::new(),
    no_duplicate_case::NoDuplicateCase::new(),
    no_empty_character_class::NoEmptyCharacterClass::new(),
    no_empty_interface::NoEmptyInterface::new(),
    no_empty_pattern::NoEmptyPattern::new(),
    no_empty::NoEmpty::new(),
    no_ex_assign::NoExAssign::new(),
    no_explicit_any::NoExplicitAny::new(),
    no_extra_boolean_cast::NoExtraBooleanCast::new(),
    no_extra_non_null_assertion::NoExtraNonNullAssertion::new(),
    no_extra_semi::NoExtraSemi::new(),
    no_mixed_spaces_and_tabs::NoMixedSpacesAndTabs::new(),
    no_func_assign::NoFuncAssign::new(),
    no_irregular_whitespace::NoIrregularWhitespace::new(),
    no_misused_new::NoMisusedNew::new(),
    no_namespace::NoNamespace::new(),
    no_new_symbol::NoNewSymbol::new(),
    no_obj_calls::NoObjCalls::new(),
    no_octal::NoOctal::new(),
    no_prototype_builtins::NoPrototypeBuiltins::new(),
    no_regex_spaces::NoRegexSpaces::new(),
    no_setter_return::NoSetterReturn::new(),
    no_self_assign::NoSelfAssign::new(),
    no_this_alias::NoThisAlias::new(),
    no_this_before_super::NoThisBeforeSuper::new(),
    no_unexpected_multiline::NoUnexpectedMultiline::new(),
    no_unsafe_finally::NoUnsafeFinally::new(),
    no_unsafe_negation::NoUnsafeNegation::new(),
    no_with::NoWith::new(),
    prefer_as_const::PreferAsConst::new(),
    prefer_namespace_keyword::PreferNamespaceKeyword::new(),
    require_yield::RequireYield::new(),
    triple_slash_reference::TripleSlashReference::new(),
    use_isnan::UseIsNaN::new(),
    valid_typeof::ValidTypeof::new(),
    no_inferrable_types::NoInferrableTypes::new(),
    no_invalid_regexp::NoInvalidRegexp::new(),
    no_unused_labels::NoUnusedLabels::new(),
    no_shadow_restricted_names::NoShadowRestrictedNames::new(),
    no_constant_condition::NoConstantCondition::new(),
  ]
}

pub fn get_all_rules() -> Vec<Box<dyn LintRule>> {
  vec![
    adjacent_overload_signatures::AdjacentOverloadSignatures::new(),
    ban_ts_comment::BanTsComment::new(),
    ban_ts_ignore::BanTsIgnore::new(),
    ban_types::BanTypes::new(),
    ban_untagged_ignore::BanUntaggedIgnore::new(),
    ban_untagged_todo::BanUntaggedTodo::new(),
    constructor_super::ConstructorSuper::new(),
    default_param_last::DefaultParamLast::new(),
    eqeqeq::Eqeqeq::new(),
    explicit_function_return_type::ExplicitFunctionReturnType::new(),
    explicit_module_boundary_types::ExplicitModuleBoundaryTypes::new(),
    for_direction::ForDirection::new(),
    getter_return::GetterReturn::new(),
    no_array_constructor::NoArrayConstructor::new(),
    no_async_promise_executor::NoAsyncPromiseExecutor::new(),
    no_await_in_loop::NoAwaitInLoop::new(),
    no_case_declarations::NoCaseDeclarations::new(),
    no_class_assign::NoClassAssign::new(),
    no_compare_neg_zero::NoCompareNegZero::new(),
    no_cond_assign::NoCondAssign::new(),
    no_debugger::NoDebugger::new(),
    no_delete_var::NoDeleteVar::new(),
    no_dupe_args::NoDupeArgs::new(),
    no_dupe_class_members::NoDupeClassMembers::new(),
    no_dupe_else_if::NoDupeElseIf::new(),
    no_dupe_keys::NoDupeKeys::new(),
    no_duplicate_case::NoDuplicateCase::new(),
    no_empty_character_class::NoEmptyCharacterClass::new(),
    no_empty_interface::NoEmptyInterface::new(),
    no_mixed_spaces_and_tabs::NoMixedSpacesAndTabs::new(),
    no_empty_pattern::NoEmptyPattern::new(),
    no_empty::NoEmpty::new(),
    no_eval::NoEval::new(),
    no_ex_assign::NoExAssign::new(),
    no_explicit_any::NoExplicitAny::new(),
    no_extra_boolean_cast::NoExtraBooleanCast::new(),
    no_extra_non_null_assertion::NoExtraNonNullAssertion::new(),
    no_extra_semi::NoExtraSemi::new(),
    no_func_assign::NoFuncAssign::new(),
    no_irregular_whitespace::NoIrregularWhitespace::new(),
    no_misused_new::NoMisusedNew::new(),
    no_namespace::NoNamespace::new(),
    no_new_symbol::NoNewSymbol::new(),
    no_non_null_assertion::NoNonNullAssertion::new(),
    no_non_null_asserted_optional_chain::NoNonNullAssertedOptionalChain::new(),
    no_obj_calls::NoObjCalls::new(),
    no_octal::NoOctal::new(),
    no_prototype_builtins::NoPrototypeBuiltins::new(),
    no_regex_spaces::NoRegexSpaces::new(),
    no_setter_return::NoSetterReturn::new(),
    no_sparse_array::NoSparseArray::new(),
    no_self_assign::NoSelfAssign::new(),
    no_this_alias::NoThisAlias::new(),
    no_this_before_super::NoThisBeforeSuper::new(),
    no_throw_literal::NoThrowLiteral::new(),
    no_unexpected_multiline::NoUnexpectedMultiline::new(),
    no_unsafe_finally::NoUnsafeFinally::new(),
    no_unsafe_negation::NoUnsafeNegation::new(),
    no_var::NoVar::new(),
    no_with::NoWith::new(),
    prefer_as_const::PreferAsConst::new(),
    prefer_namespace_keyword::PreferNamespaceKeyword::new(),
    require_yield::RequireYield::new(),
    single_var_declarator::SingleVarDeclarator::new(),
    triple_slash_reference::TripleSlashReference::new(),
    use_isnan::UseIsNaN::new(),
    valid_typeof::ValidTypeof::new(),
    no_inferrable_types::NoInferrableTypes::new(),
    no_invalid_regexp::NoInvalidRegexp::new(),
    no_const_assign::NoConstAssign::new(),
    no_control_regex::NoControlRegex::new(),
    no_unused_labels::NoUnusedLabels::new(),
    no_unused_vars::NoUnusedVars::new(),
    no_shadow_restricted_names::NoShadowRestrictedNames::new(),
    no_constant_condition::NoConstantCondition::new(),
  ]
}