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

chore(lint): migrate to xo #4

Merged
merged 1 commit into from
Oct 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
22 changes: 0 additions & 22 deletions .eslintrc.cjs

This file was deleted.

8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
},
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"xo.enable": true,
"xo.format.enable": true,
"[javascript]": {
"editor.defaultFormatter": "samverschueren.linter-xo"
},
"[typescript]": {
"editor.defaultFormatter": "samverschueren.linter-xo"
},
"typescript.tsdk": "node_modules/typescript/lib",
"prettier.ignorePath": "./node_modules/@younho9/prettier-config/.prettierignore"
}
4 changes: 3 additions & 1 deletion babel.config.cjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const BABEL_ENV = process.env.BABEL_ENV;
const {env} = require('process');

const {BABEL_ENV} = env;
const isCJS = BABEL_ENV !== undefined && BABEL_ENV === 'cjs';
const isESM = BABEL_ENV !== undefined && BABEL_ENV === 'esm';

Expand Down
31 changes: 10 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@
"git:commit-msg": "commitlint --edit",
"git:install-hooks": "husky install",
"git:pre-commit": "lint-staged",
"lint": "yarn lint:pkgs",
"lint:pkgs": "lerna run lint --no-private --stream",
"lint:root": "eslint *.cjs",
"lint:src": "lerna run lint:src --no-private --stream",
"lint:types": "lerna run lint:types --no-private --stream",
"lint": "xo",
"pkgs": "manypkg run",
"pkgs:check": "manypkg check",
"pkgs:fix": "manypkg fix",
Expand All @@ -43,12 +39,18 @@
"prettier --write --ignore-path ./node_modules/@younho9/prettier-config/.prettierignore"
],
"*.{js,jsx,ts,tsx}": [
"eslint --fix"
"xo"
],
"package.json": [
"sort-package-json"
]
},
"xo": {
"parserOptions": {
"project": "./tsconfig.xo.json"
},
"prettier": true
},
"prettier": "@younho9/prettier-config",
"dependencies": {
"@babel/cli": "^7.15.4",
Expand All @@ -72,20 +74,6 @@
"@younho9/tsconfig": "0.1.1",
"concurrently": "6.2.1",
"cross-env": "^7.0.3",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-import-resolver-node": "0.3.6",
"eslint-import-resolver-typescript": "2.5.0",
"eslint-plugin-import": "2.24.2",
"eslint-plugin-jest": "24.5.2",
"eslint-plugin-jsdoc": "36.1.0",
"eslint-plugin-jsx-a11y": "6.4.1",
"eslint-plugin-node": "11.1.0",
"eslint-plugin-prettier": "4.0.0",
"eslint-plugin-react": "7.25.1",
"eslint-plugin-react-hooks": "4.2.0",
"eslint-plugin-tsdoc": "0.2.14",
"eslint-plugin-unicorn": "36.0.0",
"husky": "^7.0.1",
"jest": "27.2.0",
"lerna": "^4.0.0",
Expand All @@ -97,7 +85,8 @@
"ts-node": "10.2.1",
"tsd": "0.18.0",
"typedoc": "0.22.6",
"typescript": "^4.4.3"
"typescript": "^4.4.3",
"xo": "0.46.3"
},
"engines": {
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
Expand Down
4 changes: 1 addition & 3 deletions packages/babel-preset/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@
"build": "concurrently yarn:build:*",
"build:cjs": "babel src -d dist --source-maps",
"clean": "concurrently yarn:clean:*",
"clean:dist": "rimraf dist",
"lint": "concurrently yarn:lint:*",
"lint:src": "eslint src --ext .js,.jsx,.ts,.tsx"
"clean:dist": "rimraf dist"
},
"babel": {
"presets": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {declare} from '@babel/helper-plugin-utils';

/** @type {import("@types/babel__helper-plugin-utils").declare } */
export default declare((api, opts) => {
export default declare((api, options) => {
api.assertVersion(7);

const {
Expand All @@ -11,7 +11,7 @@ export default declare((api, opts) => {
isCJS = false,
isESM = false,
addModuleExports = false,
} = opts;
} = options;

const config = {
presets: [
Expand Down
4 changes: 0 additions & 4 deletions packages/eslint-plugin/.eslintrc.cjs

This file was deleted.

5 changes: 1 addition & 4 deletions packages/eslint-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@
"build:cjs": "babel src --extensions .ts,.tsx -d dist --source-maps",
"build:types": "tsc src/*.ts --emitDeclarationOnly --declaration --declarationDir dist/types",
"clean": "concurrently yarn:clean:*",
"clean:dist": "rimraf dist",
"lint": "concurrently yarn:lint:*",
"lint:src": "eslint src --ext .js,.jsx,.ts,.tsx",
"lint:types": "tsc --noEmit"
"clean:dist": "rimraf dist"
},
"dependencies": {
"@types/eslint": "7.28.0"
Expand Down
6 changes: 4 additions & 2 deletions packages/eslint-plugin/src/configs/javascript.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import type {Linter} from 'eslint';

export default {
const javascript: Linter.Config = {
extends: ['plugin:jsdoc/recommended'],
settings: {
jsdoc: {
mode: 'typescript',
},
},
} as Linter.Config;
};

export default javascript;
6 changes: 4 additions & 2 deletions packages/eslint-plugin/src/configs/jest.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import type {Linter} from 'eslint';

export default {
const jest: Linter.Config = {
env: {
jest: true,
},
extends: ['plugin:jest/recommended', 'plugin:jest/style'],
} as Linter.Config;
};

export default jest;
6 changes: 4 additions & 2 deletions packages/eslint-plugin/src/configs/react.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {Linter} from 'eslint';

export default {
const react: Linter.Config = {
parserOptions: {
ecmaFeatures: {
jsx: true,
Expand All @@ -16,4 +16,6 @@ export default {
version: 'detect',
},
},
} as Linter.Config;
};

export default react;
6 changes: 4 additions & 2 deletions packages/eslint-plugin/src/configs/recommended.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {IMPORT_RULES, UNICORN_RULES} from './rules/index.js';

const ignorePatterns = ['**/dist/*'];

export default {
const recommended: Linter.Config = {
ignorePatterns,
parserOptions: {
ecmaVersion: 2021,
Expand Down Expand Up @@ -52,4 +52,6 @@ export default {
extends: ['plugin:@younho9/jest'],
},
],
} as Linter.Config;
};

export default recommended;
7 changes: 5 additions & 2 deletions packages/eslint-plugin/src/configs/rules/import.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* eslint-disable @typescript-eslint/naming-convention */
import type {Linter} from 'eslint';

import {WARN} from '../../constants/index.js';

export default {
const IMPORT_RULES: Linter.RulesRecord = {
'import/order': [
WARN,
{
Expand All @@ -13,4 +14,6 @@ export default {
},
},
],
} as Linter.RulesRecord;
};

export default IMPORT_RULES;
7 changes: 5 additions & 2 deletions packages/eslint-plugin/src/configs/rules/node.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
/* eslint-disable @typescript-eslint/naming-convention */
import type {Linter} from 'eslint';

import {OFF} from '../../constants/index.js';

export default {
const NODE_RULES: Linter.RulesRecord = {
'node/no-missing-import': OFF,
'node/no-missing-require': OFF,
'node/no-extraneous-import': OFF,
'node/no-extraneous-require': OFF,
} as Linter.RulesRecord;
};

export default NODE_RULES;
7 changes: 5 additions & 2 deletions packages/eslint-plugin/src/configs/rules/tsdoc.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
/* eslint-disable @typescript-eslint/naming-convention */
import type {Linter} from 'eslint';

import {WARN} from '../../constants/index.js';

export default {
const TSDOC_RULES: Linter.RulesRecord = {
'tsdoc/syntax': WARN,
} as Linter.RulesRecord;
};

export default TSDOC_RULES;
7 changes: 5 additions & 2 deletions packages/eslint-plugin/src/configs/rules/unicorn.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
/* eslint-disable @typescript-eslint/naming-convention */
import type {Linter} from 'eslint';

import {ERROR} from '../../constants/index.js';

export default {
const UNICORN_RULES: Linter.RulesRecord = {
'unicorn/prefer-module': ERROR,
} as Linter.RulesRecord;
};

export default UNICORN_RULES;
6 changes: 4 additions & 2 deletions packages/eslint-plugin/src/configs/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type {Linter} from 'eslint';

import {NODE_RULES, TSDOC_RULES} from './rules/index.js';

export default {
const typescript: Linter.Config = {
parser: '@typescript-eslint/parser',
plugins: ['eslint-plugin-tsdoc'],
extends: [
Expand All @@ -14,4 +14,6 @@ export default {
...NODE_RULES,
...TSDOC_RULES,
},
} as Linter.Config;
};

export default typescript;
7 changes: 4 additions & 3 deletions packages/eslint-plugin/src/constants/rule-values.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable @typescript-eslint/naming-convention */
/**
* {@link https://eslint.org/docs/user-guide/configuring/rules#configuring-rules}
*/
export const OFF = 0;
export const WARN = 1;
export const ERROR = 2;
export const OFF = 0 as const;
export const WARN = 1 as const;
export const ERROR = 2 as const;
4 changes: 3 additions & 1 deletion packages/eslint-plugin/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import * as configs from './configs/index.js';

export default {
const eslintPlugin = {
configs,
};

export default eslintPlugin;
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('isFalsy', () => {
expect(isFalsy(``)).toBeTruthy();
expect(isFalsy(null)).toBeTruthy();
expect(isFalsy(undefined)).toBeTruthy();
expect(isFalsy(NaN)).toBeTruthy();
expect(isFalsy(Number.NaN)).toBeTruthy();
expect(isFalsy(document.all)).toBeTruthy();
});

Expand All @@ -29,7 +29,7 @@ describe('isFalsy', () => {
expect(isFalsy(12n)).toBeFalsy();
expect(isFalsy(3.14)).toBeFalsy();
expect(isFalsy(-3.14)).toBeFalsy();
expect(isFalsy(Infinity)).toBeFalsy();
expect(isFalsy(-Infinity)).toBeFalsy();
expect(isFalsy(Number.POSITIVE_INFINITY)).toBeFalsy();
expect(isFalsy(Number.NEGATIVE_INFINITY)).toBeFalsy();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('isNullish', () => {
expect(isNullish(12n)).toBeFalsy();
expect(isNullish(3.14)).toBeFalsy();
expect(isNullish(-3.14)).toBeFalsy();
expect(isNullish(Infinity)).toBeFalsy();
expect(isNullish(-Infinity)).toBeFalsy();
expect(isNullish(Number.POSITIVE_INFINITY)).toBeFalsy();
expect(isNullish(Number.NEGATIVE_INFINITY)).toBeFalsy();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('isTruthy', () => {
expect(isTruthy(``)).toBeFalsy();
expect(isTruthy(null)).toBeFalsy();
expect(isTruthy(undefined)).toBeFalsy();
expect(isTruthy(NaN)).toBeFalsy();
expect(isTruthy(Number.NaN)).toBeFalsy();
expect(isTruthy(document.all)).toBeFalsy();
});

Expand All @@ -29,7 +29,7 @@ describe('isTruthy', () => {
expect(isTruthy(12n)).toBeTruthy();
expect(isTruthy(3.14)).toBeTruthy();
expect(isTruthy(-3.14)).toBeTruthy();
expect(isTruthy(Infinity)).toBeTruthy();
expect(isTruthy(-Infinity)).toBeTruthy();
expect(isTruthy(Number.POSITIVE_INFINITY)).toBeTruthy();
expect(isTruthy(Number.NEGATIVE_INFINITY)).toBeTruthy();
});
});
3 changes: 0 additions & 3 deletions packages/guards/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@
"build:types": "tsc src/*.ts --emitDeclarationOnly --declaration --declarationDir dist/types",
"clean": "concurrently yarn:clean:*",
"clean:dist": "rimraf dist",
"lint": "concurrently yarn:lint:*",
"lint:src": "eslint src --ext .js,.jsx,.ts,.tsx",
"lint:types": "tsc --noEmit",
"test": "concurrently yarn:test:*",
"test:src": "jest --config ../../jest.config.cjs -- packages/guards"
},
Expand Down
8 changes: 4 additions & 4 deletions packages/guards/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export {default as isFalsy} from './isFalsy.js';
export {default as isKeyOf} from './isKeyOf.js';
export {default as isNullish} from './isNullish.js';
export {default as isTruthy} from './isTruthy.js';
export {default as isFalsy} from './is-falsy.js';
export {default as isKeyOf} from './is-key-of.js';
export {default as isNullish} from './is-nullish.js';
export {default as isTruthy} from './is-truthy.js';
export * from '@sniptt/guards';
File renamed without changes.
5 changes: 5 additions & 0 deletions packages/guards/src/is-key-of.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default function isKeyOf<
T extends object, // eslint-disable-line @typescript-eslint/ban-types
>(object: T) {
return (key: PropertyKey): key is keyof T => key in object;
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {Falsy, Truthy} from '@younho9/types';

import isFalsy from './isFalsy.js';
import isFalsy from './is-falsy.js';

export default function isTruthy<T>(
condition: T | Falsy,
Expand Down
Loading