Skip to content

Commit

Permalink
fix: eslint config (#594)
Browse files Browse the repository at this point in the history
Removes eslint dependency that's in a private npm package
  • Loading branch information
sseppola authored Mar 2, 2023
1 parent 09c6ebe commit 0897020
Show file tree
Hide file tree
Showing 8 changed files with 377 additions and 149 deletions.
122 changes: 114 additions & 8 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,134 @@
module.exports = {
extends: './node_modules/@ardoq/shared-configs/eslint-lib',
rules: {
'no-restricted-imports': ['error', { patterns: ['rxbeach', 'rxbeach/*'] }],
'func-style': ['error', 'expression'],
extends: ['eslint:recommended', 'prettier', './eslint-typescript.js'],
plugins: ['prettier', 'import'],
env: {
es6: true,
browser: true,
},
settings: {
'import/ignore': ['node_modules'],
},
globals: {
'process': 'readonly'
process: 'readonly',
},
rules: {
'no-console': ['error', { allow: ["warn", "error"]}],
'no-shadow': ['off'],
'@typescript-eslint/no-shadow': ['error']
'no-restricted-globals': [
'error',
{
name: 'fdescribe',
message: 'Do not commit "fdescribe". Use "describe" instead.',
},
{
name: 'fit',
message: 'Do not commit "fit". Use "it" instead.',
},
],
'no-restricted-properties': [
'error',
{
object: 'describe',
property: 'only',
message: 'Do not commit "describe.only". Use "describe" instead.',
},
{
object: 'it',
property: 'only',
message: 'Do not commit "it.only". Use "it" instead.',
},
],
'prettier/prettier': ['error'],
'import/first': ['error'],
'import/no-cycle': ['error'],
camelcase: [
'error',
{
allow: [
'^UNSAFE_',
'^LEGACY_',
'^DANGEROUS_',
'^DEPRECATED_',
'^__DS_ONLY_',
],
},
],
'arrow-spacing': ['error'],
'block-scoped-var': ['off'],
'dot-notation': ['error'],
'func-call-spacing': ['off'],
'new-parens': ['error'],
'no-array-constructor': ['error'],
'no-console': ['error'],
'no-debugger': ['error'],
'no-empty': ['error'],
'no-constant-condition': ['error', { checkLoops: false }],
'no-irregular-whitespace': ['error', { skipTemplates: true }],
'no-label-var': ['error'],
'no-lonely-if': ['error'],
'no-new-object': ['error'],
'no-param-reassign': ['error'],
'no-redeclare': ['error'],
'no-return-assign': ['error'],
'no-self-compare': ['error'],
'no-shadow-restricted-names': ['error'],
'no-trailing-spaces': ['error'],
'no-undef-init': ['error'],
'no-unneeded-ternary': ['error'],
'no-useless-call': ['error'],
'no-useless-escape': ['error'],
'no-void': ['error'],
radix: ['error'],
strict: ['error', 'never'],
eqeqeq: ['error', 'always'],
'spaced-comment': ['error', 'always'],
'comma-dangle': [
'error',
{
arrays: 'always-multiline',
objects: 'always-multiline',
imports: 'always-multiline',
exports: 'always-multiline',
},
],
'no-shadow': 'off', // https://typescript-eslint.io/rules/no-shadow
'padded-blocks': ['error', 'never'],
'no-unused-expressions': ['error'],
'prefer-template': ['error'],
'no-else-return': ['error'],
'class-methods-use-this': [
'error',
{
exceptMethods: [
'componentDidMount',
'componentDidUpdate',
'componentWillMount',
'componentWillReceiveProps',
'componentWillUnmount',
'componentWillUpdate',
'render',
'shouldComponentUpdate',
],
},
],
'sort-imports': ['warn', { ignoreDeclarationSort: true }],
'no-restricted-imports': ['error', { patterns: ['rxbeach', 'rxbeach/*'] }],
'func-style': ['error', 'expression'],
},
overrides: [
{
files: ['*.tspec.ts'],
env: {
mocha: true,
node: true,
},
rules: {
'@typescript-eslint/no-unused-vars': ['off'],
camelcase: ['off'],
'prefer-const': ['off'],
},
},
{
files: ['.eslintrc.js', 'eslint-typescript.js'],
env: { node: true },
},
],
};
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ dist
.nyc_output
coverage
.idea
*.log
57 changes: 57 additions & 0 deletions eslint-typescript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
module.exports = {
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:import/typescript',
],
plugins: ['@typescript-eslint', 'prettier', 'import'],
parser: '@typescript-eslint/parser',
parserOptions: {
sourceType: 'module',
ecmaVersion: 2018,
ecmaFeatures: {
jsx: true,
},
},
rules: {
'@typescript-eslint/explicit-function-return-type': ['off'],
'@typescript-eslint/explicit-member-accessibility': ['off'],
'@typescript-eslint/no-explicit-any': ['off'],
'@typescript-eslint/no-non-null-assertion': ['off'],
'@typescript-eslint/consistent-type-assertions': [
'error',
{
assertionStyle: 'as',
objectLiteralTypeAssertions: 'allow',
},
],
'@typescript-eslint/no-shadow': ['error'],
'@typescript-eslint/no-unused-vars': ['error'],
'@typescript-eslint/no-use-before-define': ['off'],
'@typescript-eslint/prefer-interface': ['off'],
'@typescript-eslint/naming-convention': [
'error',
{
selector: 'default',
filter: {
regex: '^(?:UNSAFE|LEGACY|DANGEROUS|DEPRECATED)_',
match: true,
},
format: null,
},
],
'@typescript-eslint/explicit-module-boundary-types': ['off'],
'@typescript-eslint/func-call-spacing': ['error'],
'@typescript-eslint/member-ordering': [
'error',
{
classes: [
'static-field',
'static-method',
'instance-field',
'constructor',
'instance-method',
],
},
],
},
};
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
"postpublish": "pinst --enable"
},
"devDependencies": {
"@ardoq/shared-configs": "0.1.34",
"@ava/typescript": "3.0.1",
"@commitlint/cli": "17.1.2",
"@commitlint/config-conventional": "17.1.0",
Expand Down Expand Up @@ -83,7 +82,7 @@
"sinon": "14.0.0",
"standard-version": "9.5.0",
"tap-xunit": "2.4.1",
"typescript": "4.8.3"
"typescript": "4.9.3"
},
"dependencies": {
"rxjs-interop": "2.0.0",
Expand Down
6 changes: 3 additions & 3 deletions src/types/helpers.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import test from 'ava';
import { actionCreator } from '../actionCreator';
import { isValidRxBeachAction, isActionOfType } from './helpers';
import { isActionOfType, isValidRxBeachAction } from './helpers';

const actionCreatorWithPayload = actionCreator<string>('[test] with payload');
const actionCreatorWithoutPayload = actionCreator('[test] no payload');
Expand All @@ -23,7 +23,7 @@ test('isValidRxBeachAction - invalid actions', (t) => {
{ meta: {}, payload: {} },
];

for (let action of invalidActions) {
for (const action of invalidActions) {
t.is(isValidRxBeachAction(action), false);
}
});
Expand All @@ -35,7 +35,7 @@ test('isValidRxBeachAction - valid actions', (t) => {
actionCreatorWithoutPayload(),
];

for (let action of validActions) {
for (const action of validActions) {
t.is(isValidRxBeachAction(action), true);
}
});
Expand Down
8 changes: 4 additions & 4 deletions src/types/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Observable } from 'rxjs';
import {
ActionCreator,
ActionCreatorWithoutPayload,
ActionCreatorWithPayload,
ActionCreatorWithoutPayload,
} from './ActionCreator';
import { UnknownAction } from '../internal/types';
import { Action, VoidPayload } from './Action';
Expand Down Expand Up @@ -49,16 +49,16 @@ export const isValidRxBeachAction = (
* Assert that an action creator is of a specific type, and extract its payload
* type
*/
export function isActionOfType<T = VoidPayload>(
export const isActionOfType = <T = VoidPayload>(
creatorFn: ActionCreator<T>,
action: unknown
): action is Action<T> {
): action is Action<T> => {
if (!isValidRxBeachAction(action)) {
return false;
}

return action.type === creatorFn.type;
}
};

/**
* Type helper to infer the payload of an action creator.
Expand Down
3 changes: 2 additions & 1 deletion src/types/helpers.tspec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ for (const [creatorFn, action] of actionPairs) {

const action = actionCreatorWithoutPayload();
if (isActionOfType(actionCreatorWithoutPayload, action)) {
// @ts-expect-error
// @ts-expect-error Assert that ActionWithoutPayload does not have a payload
// eslint-disable-next-line no-unused-expressions
action.payload;
}
Loading

0 comments on commit 0897020

Please sign in to comment.