Skip to content
This repository has been archived by the owner on Jul 11, 2024. It is now read-only.

Commit

Permalink
test: verify all rules are exported (#22)
Browse files Browse the repository at this point in the history
Included: update of deps
  • Loading branch information
timdeschryver committed May 31, 2020
1 parent 6858a75 commit 084393f
Show file tree
Hide file tree
Showing 20 changed files with 4,699 additions and 2,462 deletions.
5 changes: 3 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
extends: [
'plugin:@typescript-eslint/eslint-recommended',
Expand All @@ -11,9 +12,9 @@ module.exports = {
sourceType: 'module',
},
parserOptions: {
project: './tsconfig.json',
project: './tsconfig.eslint.json',
},
rules: {
'@typescript-eslint/explicit-function-return-type': 0,
'@typescript-eslint/explicit-module-boundary-types': 'off',
},
}
7,037 changes: 4,642 additions & 2,395 deletions package-lock.json

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@
},
"devDependencies": {
"@types/common-tags": "^1.8.0",
"@types/eslint": "^4.16.8",
"@types/jest": "^24.9.1",
"@types/node": "^12.12.42",
"@typescript-eslint/eslint-plugin": "^1.13.0",
"@typescript-eslint/parser": "^1.13.0",
"@types/eslint": "^6.8.1",
"@types/jest": "^25.2.3",
"@types/node": "^14.0.6",
"@typescript-eslint/eslint-plugin": "^3.0.2",
"@typescript-eslint/parser": "^3.0.2",
"common-tags": "^1.8.0",
"cpy-cli": "^3.1.1",
"eslint": "^6.8.0",
"eslint": "^7.1.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-prettier": "^3.1.3",
"husky": "^3.1.0",
"jest": "^24.9.0",
"lint-staged": "^9.5.0",
"prettier": "^1.19.1",
"husky": "^4.2.5",
"jest": "^26.0.1",
"lint-staged": "^10.2.7",
"prettier": "^2.0.5",
"rimraf": "^3.0.2",
"ts-jest": "^26.0.0",
"typescript": "^3.9.3"
Expand Down
4 changes: 2 additions & 2 deletions src/rules/action-hygiene.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ESLintUtils, TSESTree } from '@typescript-eslint/experimental-utils'

import { docsUrl, actionCreator } from './utils'
import { docsUrl, actionCreator } from '../utils'

export const ruleName = 'action-hygiene'

Expand All @@ -25,7 +25,7 @@ export default ESLintUtils.RuleCreator(docsUrl)<Options, MessageIds>({
},
},
defaultOptions: [],
create: context => {
create: (context) => {
return {
[actionCreator](node: TSESTree.CallExpression) {
if (node.arguments && node.arguments[0].type === 'Literal') {
Expand Down
7 changes: 2 additions & 5 deletions src/rules/avoid-dispatching-multiple-actions-sequentially.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ESLintUtils, TSESTree } from '@typescript-eslint/experimental-utils'

import { multipleActionDispatch, docsUrl } from './utils'
import { multipleActionDispatch, docsUrl } from '../utils'

export const ruleName = 'avoid-dispatching-multiple-actions-sequentially'

Expand All @@ -16,9 +16,6 @@ export default ESLintUtils.RuleCreator(docsUrl)<Options, MessageIds>({
docs: {
category: 'Possible Errors',
description: 'It is recommended to only dispatch one action at a time.',
extraDescription: [
'See more at https://redux.js.org/style-guide/style-guide#avoid-dispatching-many-actions-sequentially',
],
recommended: 'error',
},
schema: [],
Expand All @@ -28,7 +25,7 @@ export default ESLintUtils.RuleCreator(docsUrl)<Options, MessageIds>({
},
},
defaultOptions: [],
create: context => {
create: (context) => {
return {
[multipleActionDispatch](node: TSESTree.CallExpression) {
context.report({
Expand Down
8 changes: 4 additions & 4 deletions src/rules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ const ruleNames = {

export const rules = {
[ruleNames.actionHygieneRuleName]: actionHygiene,
[ruleNames.noEffectDecoratorAndCreatorRuleName]: noEffectDecoratorAndCreator,
[ruleNames.noTypedStoreRuleName]: noTypedStore,
[ruleNames.avoidDispatchingMultipleActionsSequentiallyRuleName]: avoidDispatchingMultipleActionsSequentially,
[ruleNames.noMultipleStoresRuleName]: noMultipleStores,
[ruleNames.noDispatchInEffectsRuleName]: noDispatchInEffects,
[ruleNames.noEffectDecoratorAndCreatorRuleName]: noEffectDecoratorAndCreator,
[ruleNames.noEffectDecoratorRuleName]: noEffectDecorator,
[ruleNames.noEffectsInProvidersRuleName]: noEffectsInProviders,
[ruleNames.useSelectorInSelectRuleName]: useSelectorInSelect,
[ruleNames.noMultipleStoresRuleName]: noMultipleStores,
[ruleNames.noTypedStoreRuleName]: noTypedStore,
[ruleNames.onFunctionExplicitReturnTypeRuleName]: onFunctionExplicitReturnType,
[ruleNames.useSelectorInSelectRuleName]: useSelectorInSelect,
}
5 changes: 2 additions & 3 deletions src/rules/no-dispatch-in-effects.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ESLintUtils, TSESTree } from '@typescript-eslint/experimental-utils'

import { dispatchInEffects, docsUrl } from './utils'
import { dispatchInEffects, docsUrl } from '../utils'

export const ruleName = 'no-dispatch-in-effects'

Expand All @@ -16,7 +16,6 @@ export default ESLintUtils.RuleCreator(docsUrl)<Options, MessageIds>({
docs: {
category: 'Possible Errors',
description: 'An Effect should not call store.dispatch',
extraDescription: ['An action should be returned from the effect'],
recommended: 'error',
},
schema: [],
Expand All @@ -25,7 +24,7 @@ export default ESLintUtils.RuleCreator(docsUrl)<Options, MessageIds>({
},
},
defaultOptions: [],
create: context => {
create: (context) => {
return {
[dispatchInEffects](node: TSESTree.CallExpression) {
context.report({
Expand Down
8 changes: 2 additions & 6 deletions src/rules/no-effect-decorator-and-creator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ESLintUtils, TSESTree } from '@typescript-eslint/experimental-utils'

import { effectCreator, effectDecorator } from './utils/selectors'
import { docsUrl } from './utils'
import { effectCreator, effectDecorator, docsUrl } from '../utils'

export const ruleName = 'no-effect-decorator-and-creator'

Expand All @@ -18,9 +17,6 @@ export default ESLintUtils.RuleCreator(docsUrl)<Options, MessageIds>({
category: 'Possible Errors',
description:
'An Effect should only use the effect creator (`createEffect`) or the effect decorator (`@Effect`), but not both simultaneously',
extraDescription: [
'The Effect will fire twice when using the decorator and the create function',
],
recommended: 'error',
},
schema: [],
Expand All @@ -30,7 +26,7 @@ export default ESLintUtils.RuleCreator(docsUrl)<Options, MessageIds>({
},
},
defaultOptions: [],
create: context => {
create: (context) => {
const effects: TSESTree.ClassProperty[] = []

function isDuplicate(effect: TSESTree.ClassProperty) {
Expand Down
5 changes: 2 additions & 3 deletions src/rules/no-effect-decorator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ESLintUtils, TSESTree } from '@typescript-eslint/experimental-utils'

import { effectDecorator, docsUrl } from './utils'
import { effectDecorator, docsUrl } from '../utils'

export const ruleName = 'no-effect-decorator'

Expand All @@ -16,7 +16,6 @@ export default ESLintUtils.RuleCreator(docsUrl)<Options, MessageIds>({
docs: {
category: 'Possible Errors',
description: 'The createEffect creator function is preferred',
extraDescription: ['createEffect allows an effect to be type safe'],
recommended: 'error',
},
schema: [],
Expand All @@ -25,7 +24,7 @@ export default ESLintUtils.RuleCreator(docsUrl)<Options, MessageIds>({
},
},
defaultOptions: [],
create: context => {
create: (context) => {
return {
[effectDecorator](node: TSESTree.TSTypeReference) {
context.report({
Expand Down
9 changes: 3 additions & 6 deletions src/rules/no-effects-in-providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {
ngModuleDecorator,
ngModuleImports,
ngModuleProviders,
} from './utils/selectors'
import { docsUrl } from './utils'
docsUrl,
} from '../utils'

export const ruleName = 'no-effects-in-providers'

Expand All @@ -22,9 +22,6 @@ export default ESLintUtils.RuleCreator(docsUrl)<Options, MessageIds>({
category: 'Possible Errors',
description:
'An Effect should not be listed as a provider if it is added to the EffectsModule',
extraDescription: [
'If an Effect is registered with EffectsModule and is added as a provider, it will be registered twice',
],
recommended: 'error',
},
schema: [],
Expand All @@ -34,7 +31,7 @@ export default ESLintUtils.RuleCreator(docsUrl)<Options, MessageIds>({
},
},
defaultOptions: [],
create: context => {
create: (context) => {
const effectsInProviders: TSESTree.Identifier[] = []
const importedEffectsNames: string[] = []

Expand Down
7 changes: 3 additions & 4 deletions src/rules/no-multiple-stores.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ESLintUtils, TSESTree } from '@typescript-eslint/experimental-utils'

import { constructorExit, injectedStore, docsUrl } from './utils'
import { constructorExit, injectedStore, docsUrl } from '../utils'

export const ruleName = 'no-multiple-stores'

Expand All @@ -16,7 +16,6 @@ export default ESLintUtils.RuleCreator(docsUrl)<Options, MessageIds>({
docs: {
category: 'Possible Errors',
description: 'There should only be one store injected',
extraDescription: ['There is only one global store'],
recommended: 'error',
},
schema: [],
Expand All @@ -25,7 +24,7 @@ export default ESLintUtils.RuleCreator(docsUrl)<Options, MessageIds>({
},
},
defaultOptions: [],
create: context => {
create: (context) => {
const injectedStores: TSESTree.Identifier[] = []

return {
Expand All @@ -35,7 +34,7 @@ export default ESLintUtils.RuleCreator(docsUrl)<Options, MessageIds>({
[constructorExit]() {
injectedStores
.filter((_, i) => i > 0)
.forEach(node => {
.forEach((node) => {
context.report({
node,
messageId,
Expand Down
7 changes: 2 additions & 5 deletions src/rules/no-typed-store.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ESLintUtils, TSESTree } from '@typescript-eslint/experimental-utils'

import { typedStore, docsUrl } from './utils'
import { typedStore, docsUrl } from '../utils'

export const ruleName = 'no-typed-store'

Expand All @@ -16,9 +16,6 @@ export default ESLintUtils.RuleCreator(docsUrl)<Options, MessageIds>({
docs: {
category: 'Possible Errors',
description: 'Store should not be typed',
extraDescription: [
'This rule forces the usage of selectors, which are typed',
],
recommended: 'error',
},
schema: [],
Expand All @@ -28,7 +25,7 @@ export default ESLintUtils.RuleCreator(docsUrl)<Options, MessageIds>({
},
},
defaultOptions: [],
create: context => {
create: (context) => {
return {
[typedStore](node: TSESTree.TSTypeReference) {
context.report({
Expand Down
7 changes: 2 additions & 5 deletions src/rules/on-function-explicit-return-type.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ESLintUtils, TSESTree } from '@typescript-eslint/experimental-utils'

import { onFunctionWithoutType, docsUrl } from './utils'
import { onFunctionWithoutType, docsUrl } from '../utils'

export const ruleName = 'on-function-explicit-return-type'

Expand All @@ -16,9 +16,6 @@ export default ESLintUtils.RuleCreator(docsUrl)<Options, MessageIds>({
docs: {
category: 'Possible Errors',
description: 'On function should have an explicit return type',
extraDescription: [
'This rule forces the on function to have an explicit return type when defined with an arrow function.',
],
recommended: 'error',
},
schema: [],
Expand All @@ -28,7 +25,7 @@ export default ESLintUtils.RuleCreator(docsUrl)<Options, MessageIds>({
},
},
defaultOptions: [],
create: context => {
create: (context) => {
return {
[onFunctionWithoutType](node: TSESTree.TSTypeReference) {
context.report({
Expand Down
7 changes: 2 additions & 5 deletions src/rules/use-selector-in-select.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ESLintUtils, TSESTree } from '@typescript-eslint/experimental-utils'

import { select, docsUrl } from './utils'
import { select, docsUrl } from '../utils'

export const ruleName = 'use-selector-in-select'

Expand All @@ -17,9 +17,6 @@ export default ESLintUtils.RuleCreator(docsUrl)<Options, MessageIds>({
category: 'Possible Errors',
description:
'Using a selector in a select function is preferred in favor of strings/props drilling',
extraDescription: [
'A selector is more performant, shareable and maintainable',
],
recommended: 'error',
},
schema: [],
Expand All @@ -29,7 +26,7 @@ export default ESLintUtils.RuleCreator(docsUrl)<Options, MessageIds>({
},
},
defaultOptions: [],
create: context => {
create: (context) => {
return {
[select](node: TSESTree.Literal | TSESTree.ArrowFunctionExpression) {
context.report({
Expand Down
File renamed without changes.
File renamed without changes.
12 changes: 12 additions & 0 deletions tests/exported-rules.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import * as lib from '../src/rules'
import * as fs from 'fs'
import * as path from 'path'

const rulesDirectory = fs.readdirSync(path.join(__dirname, '../src/rules'))

it('should export all rules', () => {
const availableRules = rulesDirectory
.map((rule) => rule.replace('.ts', ''))
.filter((rule) => rule !== 'index')
expect(Object.keys(lib.rules)).toEqual(availableRules)
})
9 changes: 2 additions & 7 deletions tests/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import * as path from 'path'
import { resolve } from 'path'
import { RuleTester } from '@typescript-eslint/experimental-utils/dist/ts-eslint'

const parser = path.resolve(
__dirname,
'../../node_modules/@typescript-eslint/parser',
)

export function ruleTester() {
const ruleTester = new RuleTester({
parser,
parser: resolve('./node_modules/@typescript-eslint/parser'),
parserOptions: {
ecmaVersion: 6,
sourceType: 'module',
Expand Down
4 changes: 4 additions & 0 deletions tsconfig.eslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "./tsconfig.json",
"include": ["**/*.ts"]
}

0 comments on commit 084393f

Please sign in to comment.