Skip to content
This repository has been archived by the owner on Oct 28, 2023. It is now read-only.

Commit

Permalink
misc: Add missing eslint rules. (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
rajzik authored Jul 1, 2022
1 parent f3345f0 commit 98d2485
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 20 deletions.
2 changes: 0 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ lib/
tmp/
dist/
build/
jest.config.js
babel.config.js
webpack.config.js
build*/
\.eslintrc.js
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
root: true,
extends: ['rajzik', 'rajzik/node', 'rajzik/typescript', 'rajzik/future', 'rajzik/prettier'],
extends: ['rajzik', 'rajzik/node', 'rajzik/esnext', 'rajzik/typescript', 'rajzik/prettier'],
env: {
node: true,
},
Expand Down
2 changes: 1 addition & 1 deletion dangerfile.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable import/extensions, unicorn/import-index */
/* eslint-disable import/extensions */
const {
checkForInvalidLocks,
checkForConventionalPrefix,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"clean": "rimraf packages/*/{lib,dts,*.tsbuildinfo,node_modules}",
"format-package-json": "syncpack format",
"jest": "jest",
"lint": "eslint --cache --fix packages/*/{src,test}/**/*.{ts,tsx}",
"lint": "eslint --cache --fix packages/*/{src,test}/**/*.{ts,tsx} *.{js,jsx,ts,tsx}",
"pack": "cross-env NODE_ENV=production packemon pack --addEngines --addExports --declaration",
"postinstall": "husky install",
"prepare": "yarn build && husky install",
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module.exports = {
'rajzik',
'rajzik/node',
'rajzik/react',
'rajzik/future',
'rajzik/esnext',
'rajzik/typescript',
'rajzik/prettier',
],
Expand All @@ -35,7 +35,7 @@ module.exports = {
- Enable rules for react
- node
- Enable rules for node
- future
- esnext
- Enable esnext support
- typescript
- Enable support for typescript
Expand Down
1 change: 1 addition & 0 deletions packages/eslint-config/src/esnext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './presets/esnext';
1 change: 0 additions & 1 deletion packages/eslint-config/src/future.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import futureRules from '../rules/future';
import unicornRules from '../rules/esnext';

import type eslint from 'eslint';

const config: eslint.Linter.Config = {
rules: futureRules,
rules: unicornRules,
};

export default config;
4 changes: 1 addition & 3 deletions packages/eslint-config/src/rules/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,7 @@ const importRules: eslint.Linter.Config['rules'] = {
'import/group-exports': 'off', // prefer named exports to be grouped together in a single export declaration
'import/max-dependencies': 'off', // limit the maximum number of dependencies a module can have
'import/no-internal-modules': 'off', // prevent importing the submodules of other modules
/* TODO [enable this when https://github.com/benmosher/eslint-plugin-import/issues/1998 is fixed]: 'import/named': 'error', // ensure named imports correspond to a named export in the remote file */
'import/named': 'off', // ensure named imports correspond to a named export in the remote file
'import/named': 'error', // ensure named imports correspond to a named export in the remote file
'import/namespace': 'off', // ensure imported namespaces contain dereferenced properties as they are dereferenced
'import/newline-after-import': 'warn', // enforce a newline after import statements
'import/no-absolute-path': 'error', // forbid import of modules using absolute paths
Expand Down Expand Up @@ -492,7 +491,6 @@ const unicornRules: eslint.Linter.Config['rules'] = {
'unicorn/escape-case': 'warn', // require escape sequences to use uppercase values
'unicorn/explicit-length-check': 'off', // enforce explicitly comparing the length property of a value
'unicorn/filename-case': 'off', // enforce a case style for filenames
'unicorn/import-index': 'error', // enforce importing index files with .
'unicorn/import-style': 'warn', // enforce specific import styles per module
'unicorn/new-for-builtins': 'warn', // enforce the use of new for all builtins, except String, Number, Boolean, Symbol and BigInt
'unicorn/no-abusive-eslint-disable': 'error', // enforce specifying rules to disable in eslint-disable comments
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type eslint from 'eslint';

const futureRules: eslint.Linter.Config['rules'] = {
const unicornRules: eslint.Linter.Config['rules'] = {
// eslint-plugin-unicorn rules
'unicorn/no-array-for-each': 'off', // prefer for…of over Array#forEach(…)
'unicorn/no-array-method-this-argument': 'error', // disallow using the this argument in array methods
Expand Down Expand Up @@ -42,13 +42,14 @@ const futureRules: eslint.Linter.Config['rules'] = {
'unicorn/prefer-dom-node-dataset': 'warn', // prefer using .dataset on DOM elements over .setAttribute(…)
'unicorn/prefer-dom-node-remove': 'warn', // prefer childNode.remove() over parentNode.removeChild(childNode)
'unicorn/prefer-dom-node-text-content': 'warn', // prefer .textContent over .innerText
'unicorn/prefer-event-target': 'error', // Prefer EventTarget over EventEmitter
'unicorn/prefer-export-from': ['error', { ignoreUsedVariables: true }], // prefer export…from when re-exporting
'unicorn/prefer-includes': 'warn', // prefer .includes() over .indexOf() when checking for existence or non-existence
'unicorn/prefer-json-parse-buffer': 'off', // prefer reading a JSON file as a buffer
'unicorn/prefer-keyboard-event-key': 'warn', // prefer KeyboardEvent#key over KeyboardEvent#keyCode
'unicorn/prefer-math-trunc': 'warn', // enforce the use of Math.trunc instead of bitwise operators
'unicorn/prefer-modern-dom-apis': 'error',
'unicorn/prefer-modern-math-apis': 'error',
'unicorn/prefer-modern-dom-apis': 'error', // Prefer .before() over .insertBefore(), .replaceWith() over .replaceChild(), prefer one of .before(), .after(), .append() or .prepend() over insertAdjacentText() and insertAdjacentElement()
'unicorn/prefer-modern-math-apis': 'error', // Prefer modern Math APIs over legacy patterns
// FIXME [@rajzik]: This is good rule but adoption isn't great so far
'unicorn/prefer-module': 'off', // Prefer JavaScript modules (ESM) over CommonJS
'unicorn/prefer-node-protocol': 'warn', // Prefer using the `node:` protocol when importing Node.js builtin modules
Expand All @@ -60,6 +61,7 @@ const futureRules: eslint.Linter.Config['rules'] = {
'unicorn/prefer-query-selector': 'off', // prefer .querySelector() over .getElementById(), .querySelectorAll() over .getElementsByClassName() and .getElementsByTagName()
'unicorn/prefer-reflect-apply': 'off', // prefer Reflect.apply() over Function#apply()
'unicorn/prefer-regexp-test': 'warn', // prefer RegExp#test() over String#match() and RegExp#exec()
'unicorn/prefer-logical-operator-over-ternary': 'error', // Prefer using a logical operator over a ternary
'unicorn/prefer-set-has': 'warn', // prefer Set#has() over Array#includes() when checking for existence or non-existence
'unicorn/prefer-spread': 'error', // prefer the spread operator over Array.from()
'unicorn/prefer-string-replace-all': 'warn', // prefer String#replaceAll() over regex searches with the global flag
Expand All @@ -81,4 +83,8 @@ const futureRules: eslint.Linter.Config['rules'] = {
'unicorn/throw-new-error': 'error', // require new when throwing an error
};

export default futureRules;
const config = {
...unicornRules,
};

export default config;
6 changes: 3 additions & 3 deletions packages/eslint-config/tools/check-rules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import nodeRulesConfig from '../../src/rules/node';
import baseRulesConfig from '../../src/rules/base';
import reactRulesConfig from '../../src/rules/react';
import typescriptRulesPreset from '../../src/presets/typescript';
import unicornPreset from '../../src/presets/future';
import esnextPreset from '../../src/presets/esnext';

import prettierConfig from '../../src/presets/prettier';

Expand All @@ -18,7 +18,7 @@ const reactRules = Object.entries(reactRulesConfig!).map(([ruleName]) => ruleNam
const typescriptRules = Object.entries(typescriptRulesPreset!.overrides![0]!.rules!).map(
([ruleName]) => ruleName,
);
const unicornRules = Object.entries(unicornPreset.rules!).map(([ruleName]) => ruleName);
const esnextRules = Object.entries(esnextPreset.rules!).map(([ruleName]) => ruleName);

const usedRules = [
...jestRules,
Expand All @@ -27,7 +27,7 @@ const usedRules = [
...baseRules,
...reactRules,
...typescriptRules,
...unicornRules,
...esnextRules,
].sort();

const missingRules: string[] = [];
Expand Down

0 comments on commit 98d2485

Please sign in to comment.