Skip to content

Commit

Permalink
feat!: update rules and deps (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Nov 8, 2022
1 parent a23e7cb commit eb68e52
Show file tree
Hide file tree
Showing 15 changed files with 3,782 additions and 4,513 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:

strategy:
matrix:
node: [12]
node: [14]
os: [ubuntu-latest]

steps:
Expand Down Expand Up @@ -51,7 +51,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node: [12, 14, 16, 17]
node: [14, 16, 18]
os: [ubuntu-latest, windows-latest, macos-latest]

steps:
Expand Down
6 changes: 3 additions & 3 deletions __tests__/fixtures/good.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,9 +469,9 @@ function doSomething() {
async function fooAsync() {
const result = await doSomething();

Object.keys(result).forEach((item) => {
item.sum += 1;
});
for (const item of Object.keys(result)) {
trailingCommasInFUnctionSyntax(item, item);
}

return result;
}
Expand Down
4 changes: 2 additions & 2 deletions __tests__/fixtures/jsdoc-typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ const var9 = { a: "str", b: 1 };
/**
* A map-like object that maps arbitrary `string` properties to `number`s.
*
* @type {Object.<string, number>}
* @type {Object<string, number>}
*/
const stringToNumber = { test: 123 };

/** @type {Object.<number, object>} */
/** @type {Object<number, object>} */
const arrayLike = [];

arrayLike[1] = { foo: "bar" };
Expand Down
6 changes: 3 additions & 3 deletions __tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -665,11 +665,11 @@ test("should load the 'html' preset", async (t) => {
},
});

const configForFile = await await cli.calculateConfigForFile("index.html");
const configForFile = await cli.calculateConfigForFile("index.html");

t.true(configForFile.plugins.includes("html"));

const validReport = await await cli.lintText(
const validReport = await cli.lintText(
`<!DOCTYPE html>
<html>
<head>
Expand All @@ -692,7 +692,7 @@ test("should load the 'html' preset", async (t) => {
t.is(validReport[0].errorCount, 0, "eslint report without errors");
t.is(validReport[0].warningCount, 0, "eslint report without warnings");

const invalidReport = await await cli.lintText(
const invalidReport = await cli.lintText(
`<!DOCTYPE html>
<html>
<head>
Expand Down
2 changes: 2 additions & 0 deletions lib/config/rules/best-practices.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ module.exports = {
// Disallow use of empty functions
// We're all grown ups here... Hope so
"no-empty-function": "off",
// Disallow empty static blocks
"no-empty-static-block": "error",
// Disallow use of empty destructuring patterns
"no-empty-pattern": "error",
// Disallow comparisons to null without a type-checking operator
Expand Down
2 changes: 2 additions & 0 deletions lib/config/rules/ecmascript-6.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ module.exports = {
"no-confusing-arrow": "off",
// Disallow modifying variables that are declared using const
"no-const-assign": "error",
// Disallow expressions where the operation doesn't affect the value
"no-constant-binary-expression": "error",
// Disallow duplicate name in class members
"no-dupe-class-members": "error",
// Disallow duplicate module imports
Expand Down
25 changes: 21 additions & 4 deletions lib/config/rules/jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ module.exports = {
"jest/consistent-test-it": "error",
// Enforce assertion to be made in a test body
"jest/expect-expect": "error",
// Disallow capitalized test names
"jest/prefer-lowercase-title": "error",
// Enforces a maximum number assertion calls in a test body
"jest/max-expects": "off",
// Enforces a maximum depth to nested describe calls
"jest/max-nested-describe": "off",
// Disallow alias methods
"jest/no-alias-methods": "error",
// Disallow commented out tests
"jest/no-commented-out-tests": "error",
// Disallow conditional logic in tests
// Sometimes you have a code inside test, so it is hard to follow this
"jest/no-conditional-in-test": "off",
// Disallow commented out tests
"jest/no-conditional-expect": "error",
// Disallow use of deprecated functions
Expand All @@ -39,10 +42,10 @@ module.exports = {
"jest/no-interpolation-in-snapshots": "error",
// Disallow Jasmine globals
"jest/no-jasmine-globals": "error",
// Disallow importing `jest`
"jest/no-jest-import": "error",
// Disallow large snapshots
"jest/no-large-snapshots": "off",
// Disallow specific jest. methods
"jest/no-restricted-jest-methods": "off",
// Disallow manually importing from __mocks__
"jest/no-mocks-import": "error",
// Disallow specific matchers & modifiers
Expand All @@ -61,12 +64,26 @@ module.exports = {
"jest/no-test-return-statement": "off",
// Suggest using `toBeCalledWith()` OR `toHaveBeenCalledWith()`
"jest/prefer-called-with": "off",
// Suggest using the built-in comparison matchers
"jest/prefer-comparison-matcher": "error",
// Reports where you might be able to use .each instead of native loops.
"jest/prefer-each": "error",
// Jest has built-in matchers for expecting equality, which allow for more readable tests and error messages if an expectation fails.
"jest/prefer-equality-matcher": "error",
// Suggest using `expect.assertions()` OR `expect.hasAssertions()`
"jest/prefer-expect-assertions": "off",
// Prefer `await expect(...).resolves` over `expect(await ...)` syntax
"jest/prefer-expect-resolves": "error",
// Prefer having hooks in a consistent order
"jest/prefer-hooks-in-order": "error",
// Suggest to have all hooks at top-level before tests
"jest/prefer-hooks-on-top": "error",
// Disallow capitalized test names
"jest/prefer-lowercase-title": "error",
// Prefer mock resolved/rejected shorthands for promises
"jest/prefer-mock-promise-shorthand": "error",
// Prefer including a hint with external snapshots
"jest/prefer-snapshot-hint": "off",
// Suggest using `jest.spyOn()`
"jest/prefer-spy-on": "error",
// Suggest using `toStrictEqual()`
Expand Down
5 changes: 5 additions & 0 deletions lib/config/rules/jsdoc-typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,13 @@ module.exports = {
"jsdoc/require-yields": "off",
// Ensures that if a @yields is present that a yield (or yield with a value) is present in the function body (or that if a @next is present that there is a yield with a return value present).
"jsdoc/require-yields-check": "off",
// Sorts tags by a specified sequence according to tag name.
// TODO enable in future?
"jsdoc/sort-tags": "off",
// Enforces lines (or no lines) between tags.
"jsdoc/tag-lines": ["error", "never"],
// This rule may be desirable if your text is known not to contain HTML or Markdown and you therefore do not wish for it to be accidentally interpreted as such by the likes of Visual Studio Code or if you wish to view it escaped within it or your documentation.
"jsdoc/text-escaping": "off",
// Requires all types to be valid JSDoc, Closure, or TypeScript compiler types without syntax errors.
"jsdoc/valid-types": "off",
};
2 changes: 2 additions & 0 deletions lib/config/rules/possible-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ module.exports = {
"no-loss-of-precision": "error",
// Disallow characters which are made with multiple code points in character class syntax
"no-misleading-character-class": "error",
// Disallow new operators with global non-constructor functions
"no-new-native-nonconstructor": "error",
// Disallow the use of object properties of the global object (Math and JSON) as functions
"no-obj-calls": "error",
// Disallow returning values from Promise executor functions
Expand Down
7 changes: 7 additions & 0 deletions lib/config/rules/react.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ module.exports = {
],
// Enforce a specific function type for function components
"react/function-component-definition": "off",
// This rule checks whether the value and setter variables destructured from a React.useState() call are named symmetrically.
// TODO add `allowDestructuredState`
"react/hook-use-state": "error",
// The sandbox attribute enables an extra set of restrictions for the content in the iframe. Using sandbox attribute is considered a good security practice.
"react/iframe-missing-sandbox": "error",
// Forbid foreign propTypes
"react/forbid-foreign-prop-types": ["error", { allowInPropTypes: true }],
// Prevent using Array index in key props
Expand Down Expand Up @@ -282,6 +287,8 @@ module.exports = {
"react/jsx-no-comment-textnodes": "error",
// Prevents JSX context provider values from taking values that will cause needless rerenders.
"react/jsx-no-constructed-context-values": "error",
// Using the && operator to render some element conditionally in JSX can cause unexpected values being rendered, or even crashing the rendering.
"react/jsx-no-leaked-render": "error",
// Prevent duplicate props in JSX
"react/jsx-no-duplicate-props": ["error", { ignoreCase: true }],
// Prevent usage of unwrapped JSX strings
Expand Down
2 changes: 0 additions & 2 deletions lib/config/rules/stylistic-issues.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,10 +378,8 @@ module.exports = {
},
],
// Disallow the use of Math.pow in favor of the ** operator
// TODO should be enabled/disabled based ECMA scripts
"prefer-exponentiation-operator": "error",
// Disallow using Object.assign with an object literal as the first argument and prefer the use of object spread instead.
// TODO should be enabled/disabled based ECMA scripts
"prefer-object-spread": "error",
// Require quotes around object literal property names
// Prettier does the job
Expand Down
34 changes: 23 additions & 11 deletions lib/config/rules/unicorn.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ module.exports = {
// Enforce a specific parameter name in catch clauses
"unicorn/catch-error-name": ["error", { ignore: [/^ignore/i] }],
// Use destructured variables over properties
// TODO maybe enable in future
"unicorn/consistent-destructuring": "off",
// Move function definitions to the highest possible scope
"unicorn/consistent-function-scoping": "off",
Expand All @@ -22,7 +21,6 @@ module.exports = {
// Require escape sequences to use uppercase values
"unicorn/escape-case": "error",
// Add expiration conditions to T_O_D_O comments
// TODO maybe enable in future
"unicorn/expiring-todo-comments": "off",
// Enforce explicitly comparing the `length` property of a value
"unicorn/explicit-length-check": "error",
Expand Down Expand Up @@ -62,9 +60,8 @@ module.exports = {
"unicorn/no-abusive-eslint-disable": "error",
// Prevent passing a function reference directly to iterator methods.
"unicorn/no-array-callback-reference": "off",
// TODO Enable in future
// Prefer `for…of` over `Array.forEach(…)`
"unicorn/no-array-for-each": "off",
"unicorn/no-array-for-each": "error",
// TODO Maybe enable in future
// Disallow using the `this` argument in array methods.
"unicorn/no-array-method-this-argument": "off",
Expand All @@ -80,7 +77,6 @@ module.exports = {
// "unicorn/no-document-cookie": "off",
// Disallow empty files
"unicorn/no-empty-file": "error",
// TODO maybe enable in future
// Do not use a `for` loop that can be replaced with a `for-of` loop
"unicorn/no-for-loop": "off",
// Enforce the use of unicode escapes instead of hexadecimal escapes.
Expand All @@ -93,7 +89,6 @@ module.exports = {
"unicorn/no-keyword-prefix": "off",
// Disallow `if` statements as the only statement in `if` blocks without `else`
"unicorn/no-lonely-if": "error",
// TODO maybe enable in future, now conflict with prettier
// Improved version of the no-nested-ternary ESLint rule, which allows cases where the nested ternary is only one level and wrapped in parens.
"unicorn/no-nested-ternary": "off",
// Disallow `new Array()`
Expand All @@ -115,8 +110,12 @@ module.exports = {
// TODO maybe enable in future
// Disallow assigning `this` to a variable
"unicorn/no-this-assignment": "off",
// Disallow awaiting non-promise values
"unicorn/no-unnecessary-await": "error",
// Disallow unreadable array destructuring.
"unicorn/no-unreadable-array-destructuring": "off",
// Disallow unreadable IIFEs.
"unicorn/no-unreadable-iife": "off",
// TODO maybe enable in future
// Disallow unsafe regular expressions.
"unicorn/no-unsafe-regex": "off",
Expand All @@ -130,6 +129,8 @@ module.exports = {
"unicorn/no-useless-promise-resolve-reject": "error",
// Disallow useless spread
"unicorn/no-useless-spread": "error",
// Disallow useless case in switch statements.
"unicorn/no-useless-switch-case": "error",
// Disallow useless `undefined`
"unicorn/no-useless-undefined": "error",
// Disallow number literals with zero fractions or dangling dots
Expand Down Expand Up @@ -170,6 +171,9 @@ module.exports = {
// "unicorn/prefer-dom-node-remove": "off",
// Prefer `.textContent` over `.innerText`
// "unicorn/prefer-dom-node-text-content": "off",
// Prefer EventTarget over EventEmitter
// TODO enable it after drop node.js v14
"unicorn/prefer-event-target": "off",
// Prefer `export…from` when re-exporting
"unicorn/prefer-export-from": "error",
// Prefer `.includes()` over `.indexOf()` when checking for existence or non-existence
Expand All @@ -178,13 +182,20 @@ module.exports = {
"unicorn/prefer-json-parse-buffer": "off",
// Prefer `KeyboardEvent.key` over `KeyboardEvent.keyCode`
// "unicorn/prefer-keyboard-event-key": "off",
// Prefer using a logical operator over a ternary.
// TODO enable in future?
"unicorn/prefer-logical-operator-over-ternary": "off",
// Enforce the use of `Math.trunc` instead of bitwise operators
"unicorn/prefer-math-trunc": "error",
// Prefer `.before()` over `.insertBefore()`, `.replaceWith()` over `.replaceChild()`, prefer one of `.before()`, `.after()`, `.append()` or `.prepend()` over `insertAdjacentText()` and `insertAdjacentElement()`
// "unicorn/prefer-modern-dom-apis": "off",
// Prefer modern Math APIs over legacy patterns.
"unicorn/prefer-modern-math-apis": "error",
// Prefer JavaScript modules (ESM) over CommonJS
// We do the same in our `module` and `script` preset
"unicorn/prefer-module": "off",
// Prefer using String, Number, BigInt, Boolean, and Symbol directly.
"unicorn/prefer-native-coercion-functions": "error",
// Prefer negative index over .length - index for {String,Array,TypedArray}#slice() and Array#splice()
"unicorn/prefer-negative-index": "error",
// TODO enable in future
Expand Down Expand Up @@ -242,13 +253,14 @@ module.exports = {
// "unicorn/require-post-message-target-origin": "error",
// Enforce better string content
"unicorn/string-content": "off",
// Enforce consistent brace style for case clauses.
// TODO do we really need it?
"unicorn/switch-case-braces": "off",
// Fix whitespace-insensitive template indentation.
"unicorn/template-indent": "off",
// Enforce consistent case for text encoding identifiers
// The idea is good, but don't catch all cases
"unicorn/text-encoding-identifier-case": "off",
// Require new when throwing an error (fixable)
"unicorn/throw-new-error": "error",

// Deprecated
// TODO enabled in future
// Prefer `Object.hasOwn(…)` over `Object.prototype.hasOwnProperty.call(…)`
// "unicorn/prefer-object-has-own": "off",
};
3 changes: 3 additions & 0 deletions lib/config/rules/variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ module.exports = {
// Enforce or disallow variable initializations at definition
// Situations are different
"init-declarations": "off",
// Require or disallow logical assignment logical operator shorthand
// TODO enable after drop Node.js 14
"logical-assignment-operators": "off",
// Disallow deletion of variables
"no-delete-var": "error",
// Disallow labels that share a name with a variable
Expand Down

0 comments on commit eb68e52

Please sign in to comment.