Created
April 26, 2022 07:39
-
-
Save OliverJAsh/442d90096614495f43f48594a5749ac2 to your computer and use it in GitHub Desktop.
`no-observable-pipe` ESLint rule
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { getTypeServices } = require('eslint-etc'); | |
const { | |
ESLintUtils, | |
TSESTree, | |
TSESLint, | |
} = require('@typescript-eslint/experimental-utils'); | |
const ruleCreator = ESLintUtils.RuleCreator( | |
(_name) => | |
// This should be the URL of the docs for this rule, but since this is a custom/local rule, we | |
// don't have one. | |
'https://unsplash.com/', | |
); | |
const noObservablePipeMethod = ruleCreator({ | |
defaultOptions: [], | |
meta: { | |
docs: { | |
description: '', | |
recommended: false, | |
}, | |
messages: { | |
forbidden: '`pipe` is not allowed.', | |
}, | |
schema: [], | |
type: 'problem', | |
}, | |
name: 'no-observable-pipe-method', | |
create: (context) => { | |
/** @type {TSESLint.RuleFunction<TSESTree.MemberExpression>} */ | |
const listener = (node) => { | |
const { couldBeObservable } = getTypeServices(context); | |
if (couldBeObservable(node.object)) { | |
context.report({ | |
node, | |
messageId: 'forbidden', | |
}); | |
} | |
}; | |
return { | |
'CallExpression > MemberExpression[property.name="pipe"]': listener, | |
}; | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment