Skip to content

Instantly share code, notes, and snippets.

@OliverJAsh
Created April 26, 2022 07:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OliverJAsh/442d90096614495f43f48594a5749ac2 to your computer and use it in GitHub Desktop.
Save OliverJAsh/442d90096614495f43f48594a5749ac2 to your computer and use it in GitHub Desktop.
`no-observable-pipe` ESLint rule
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