UNPKG

eslint-config-chain-able

Version:
56 lines (39 loc) 1.57 kB
'use strict'; /* $FlowFixMe */ const testFunctions = Object.assign(Object.create(null), { describe: true, it: true, test: true }); /** * Copyright (c) 2014-present, Facebook, Inc. All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. * * */const matchesTestFunction = object => object && testFunctions[object.name];const isCallToFocusedTestFunction = object => object && object.name[0] === 'f' && testFunctions[object.name.substring(1)];const isPropertyNamedOnly = property => property && (property.name === 'only' || property.value === 'only'); const isCallToTestOnlyFunction = callee => matchesTestFunction(callee.object) && isPropertyNamedOnly(callee.property); module.exports = context => ({ CallExpression(node) { const callee = node.callee; if (!callee) { return; } if ( callee.type === 'MemberExpression' && isCallToTestOnlyFunction(callee)) { context.report({ message: 'Unexpected focused test.', node: callee.property }); return; } if (callee.type === 'Identifier' && isCallToFocusedTestFunction(callee)) { context.report({ message: 'Unexpected focused test.', node: callee }); return; } } });