Socket
Socket
Sign inDemoInstall

eslint-plugin-unicorn

Package Overview
Dependencies
Maintainers
1
Versions
105
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-unicorn - npm Package Compare versions

Comparing version 40.0.0 to 40.1.0

11

package.json
{
"name": "eslint-plugin-unicorn",
"version": "40.0.0",
"version": "40.1.0",
"description": "Various awesome ESLint rules",

@@ -21,2 +21,3 @@ "license": "MIT",

"fix:md": "npm run lint:md -- --fix",
"generate-rule-notices": "node ./scripts/generate-rule-notices.mjs",
"generate-rules-table": "node ./scripts/generate-rules-table.mjs",

@@ -32,3 +33,3 @@ "generate-usage-example": "node ./scripts/generate-usage-example.mjs",

"test": "npm-run-all --continue-on-error lint test:*",
"test:js": "nyc ava"
"test:js": "c8 ava"
},

@@ -73,5 +74,6 @@ "files": [

"ava": "^3.15.0",
"c8": "^7.11.0",
"chalk": "^5.0.0",
"enquirer": "^2.3.6",
"eslint": "^8.5.0",
"eslint": "^8.6.0",
"eslint-ava-rule-tester": "^4.0.0",

@@ -88,3 +90,2 @@ "eslint-plugin-eslint-plugin": "^4.1.0",

"npm-run-all": "^4.1.5",
"nyc": "^15.1.0",
"outdent": "^0.8.0",

@@ -104,3 +105,3 @@ "typescript": "^4.5.4",

},
"nyc": {
"c8": {
"reporter": [

@@ -107,0 +108,0 @@ "text",

@@ -152,5 +152,4 @@ # eslint-plugin-unicorn [![Coverage Status](https://codecov.io/gh/sindresorhus/eslint-plugin-unicorn/branch/main/graph/badge.svg)](https://codecov.io/gh/sindresorhus/eslint-plugin-unicorn/branch/main) [![npm version](https://img.shields.io/npm/v/eslint-plugin-unicorn.svg?style=flat)](https://npmjs.com/package/eslint-plugin-unicorn)

<!-- Do not manually modify this table. Run: `npm run generate-rules-table` -->
<!-- RULES_TABLE_START -->
<!-- Do not manually modify RULES_TABLE part. Run: `npm run generate-rules-table` -->
<!-- RULES_TABLE -->
| Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Description | ✅ | 🔧 | 💡 |

@@ -254,7 +253,6 @@ | :-- | :-- | :-- | :-- | :-- |

| [string-content](docs/rules/string-content.md) | Enforce better string content. | | 🔧 | 💡 |
| [template-indent](docs/rules/template-indent.md) | Fix whitespace-insensitive template indentation. | | 🔧 | |
| [template-indent](docs/rules/template-indent.md) | Fix whitespace-insensitive template indentation. | ✅ | 🔧 | |
| [throw-new-error](docs/rules/throw-new-error.md) | Require `new` when throwing an error. | ✅ | 🔧 | |
<!-- /RULES_TABLE -->
<!-- RULES_TABLE_END -->
## Deprecated Rules

@@ -261,0 +259,0 @@

@@ -68,3 +68,3 @@ 'use strict';

// But can't reproduce, just ignore this case
/* istanbul ignore next */
/* c8 ignore next 3 */
if (!variable) {

@@ -71,0 +71,0 @@ return;

'use strict';
const {getFunctionHeadLocation, getFunctionNameWithKind} = require('eslint-utils');
const getReferences = require('./utils/get-references.js');
const {isNodeMatches} = require('./utils/is-node-matches.js');

@@ -48,3 +49,3 @@ const MESSAGE_ID = 'consistent-function-scoping';

// If we have a scope, the earlier checks should have worked so ignore them here
/* istanbul ignore next: Hard to test */
/* c8 ignore next 3 */
if (identifierScope) {

@@ -55,3 +56,3 @@ return false;

const identifierParentScope = scopeManager.acquire(identifier.parent);
/* istanbul ignore next: Hard to test */
/* c8 ignore next 3 */
if (!identifierParentScope) {

@@ -82,3 +83,3 @@ return false;

// https://reactjs.org/docs/hooks-reference.html
const reactHooks = new Set([
const reactHooks = [
'useState',

@@ -94,3 +95,4 @@ 'useEffect',

'useDebugValue',
]);
].flatMap(hookName => [hookName, `React.${hookName}`]);
const isReactHook = scope =>

@@ -100,4 +102,3 @@ scope.block

&& scope.block.parent.callee
&& scope.block.parent.callee.type === 'Identifier'
&& reactHooks.has(scope.block.parent.callee.name);
&& isNodeMatches(scope.block.parent.callee, reactHooks);

@@ -104,0 +105,0 @@ const isArrowFunctionWithThis = scope =>

@@ -189,4 +189,3 @@ 'use strict';

function reachedDate(past) {
const now = new Date().toISOString().slice(0, 10);
function reachedDate(past, now) {
return Date.parse(past) < Date.parse(now);

@@ -196,3 +195,4 @@ }

function tryToCoerceVersion(rawVersion) {
/* istanbul ignore if: version in `package.json` and comment can't be empty */
// `version` in `package.json` and comment can't be empty
/* c8 ignore next 3 */
if (!rawVersion) {

@@ -220,3 +220,4 @@ return false;

const parts = version.split(' ');
/* istanbul ignore if: We don't have this `package.json` to test */
// We don't have this `package.json` to test
/* c8 ignore next 3 */
if (parts.length > 1) {

@@ -226,3 +227,4 @@ version = parts[0];

/* istanbul ignore if: We don't have this `package.json` to test */
// We don't have this `package.json` to test
/* c8 ignore next 3 */
if (semver.valid(version)) {

@@ -237,3 +239,4 @@ return version;

} catch {
/* istanbul ignore next: We don't have this `package.json` to test */
// We don't have this `package.json` to test
/* c8 ignore next 3 */
return false;

@@ -257,2 +260,3 @@ }

allowWarningComments: true,
date: new Date().toISOString().slice(0, 10),
...context.options[0],

@@ -334,6 +338,6 @@ };

uses++;
const [date] = dates;
const [expirationDate] = dates;
const shouldIgnore = options.ignoreDatesOnPullRequests && ci.isPR;
if (!shouldIgnore && reachedDate(date)) {
if (!shouldIgnore && reachedDate(expirationDate, options.date)) {
context.report({

@@ -343,3 +347,3 @@ loc: comment.loc,

data: {
expirationDate: date,
expirationDate,
message: parseTodoMessage(comment.value),

@@ -414,3 +418,3 @@ },

/* istanbul ignore if: Can't test in Node.js */
/* c8 ignore start */
if (!hasTargetPackage || !targetPackageVersion) {

@@ -420,2 +424,3 @@ // Can't compare `¯\_(ツ)_/¯`

}
/* c8 ignore end */

@@ -444,3 +449,3 @@ const compare = semverComparisonForOperator(dependency.condition);

/* istanbul ignore if: Can't test in this repo */
/* c8 ignore next 3 */
if (!hasTargetEngine) {

@@ -545,2 +550,6 @@ continue;

},
date: {
type: 'string',
format: 'date',
},
},

@@ -547,0 +556,0 @@ },

@@ -7,3 +7,3 @@ 'use strict';

// But parentheses of `NewExpression` could be omitted, add this check to prevent accident use on it
/* istanbul ignore next */
/* c8 ignore next 3 */
if (node.type !== 'CallExpression') {

@@ -10,0 +10,0 @@ throw new Error(`Unexpected node "${node.type}".`);

@@ -20,3 +20,3 @@ 'use strict';

// If the removed argument is the only argument, the trailing comma must be removed too
/* istanbul ignore next: Not reachable for now */
/* c8 ignore start */
if (callExpression.arguments.length === 1) {

@@ -28,2 +28,3 @@ const tokenAfter = sourceCode.getTokenBefore(lastToken);

}
/* c8 ignore end */

@@ -30,0 +31,0 @@ return fixer.replaceTextRange([start, end], '');

@@ -102,3 +102,3 @@ 'use strict';

// An exotic custom parser or a bug in one could cover it too.
/* istanbul ignore next */
/* c8 ignore next */
return [];

@@ -105,0 +105,0 @@ };

@@ -192,3 +192,2 @@ 'use strict';

const create = context => {
const sourceCode = context.getSourceCode();
const rules = {};

@@ -218,3 +217,3 @@

const [iterator] = node.arguments;
return getProblem(context, iterator, method, options, sourceCode);
return getProblem(context, iterator, method, options);
};

@@ -221,0 +220,0 @@ }

@@ -322,3 +322,4 @@ 'use strict';

// Check `CallExpression.callee`
/* istanbul ignore next: Because of `ChainExpression` wrapper, `foo?.forEach()` is already failed on previous check, keep this just for safety */
// Because of `ChainExpression` wrapper, `foo?.forEach()` is already failed on previous check keep this just for safety
/* c8 ignore next 3 */
if (callExpression.callee.optional) {

@@ -325,0 +326,0 @@ return false;

@@ -37,3 +37,3 @@ 'use strict';

/* istanbul ignore next */
/* c8 ignore next */
throw new Error('Cannot find the first `Array#push()` call.\nPlease open an issue at https://github.com/sindresorhus/eslint-plugin-unicorn/issues/new?title=%60no-array-push-push%60%3A%20Cannot%20find%20first%20%60push()%60');

@@ -40,0 +40,0 @@ }

@@ -82,5 +82,4 @@ 'use strict';

fixable: 'code',
schema: [],
messages,
},
};

@@ -59,5 +59,4 @@ 'use strict';

},
schema: [],
messages,
},
};

@@ -52,5 +52,4 @@ 'use strict';

},
schema: [],
messages,
},
};

@@ -55,3 +55,3 @@ 'use strict';

/* istanbul ignore next: Can't find a case to cover this line */
/* c8 ignore next 3 */
if (parent.shorthand && parent.value.left && Boolean(keyword)) {

@@ -58,0 +58,0 @@ report(node, keyword);

@@ -143,3 +143,3 @@ 'use strict';

const classToken = sourceCode.getFirstToken(node);
/* istanbul ignore next */
/* c8 ignore next */
assertToken(classToken, {

@@ -146,0 +146,0 @@ expected: {type: 'Keyword', value: 'class'},

@@ -125,5 +125,4 @@ 'use strict';

},
schema: [],
messages,
},
};

@@ -59,4 +59,2 @@ 'use strict';

const schema = [];
/** @type {import('eslint').Rule.RuleModule} */

@@ -71,5 +69,4 @@ module.exports = {

fixable: 'code',
schema,
messages,
},
};

@@ -193,4 +193,2 @@ 'use strict';

const schema = [];
/** @type {import('eslint').Rule.RuleModule} */

@@ -205,5 +203,4 @@ module.exports = {

fixable: 'code',
schema,
messages,
},
};

@@ -81,3 +81,5 @@ 'use strict';

// `array.unshift(undefined)`
|| name === 'unshift';
|| name === 'unshift'
// `React.createContext(undefined)`
|| name === 'createContext';
};

@@ -84,0 +86,0 @@

@@ -130,3 +130,3 @@ 'use strict';

// Lower than `assignment`, should already parenthesized
/* istanbul ignore next */
/* c8 ignore next */
|| node.type === 'AssignmentExpression'

@@ -138,3 +138,3 @@ || node.type === 'YieldExpression'

const getDestructuringLeftAndRight = node => {
/* istanbul ignore next */
/* c8 ignore next 3 */
if (!node) {

@@ -141,0 +141,0 @@ return {};

@@ -54,5 +54,4 @@ 'use strict';

hasSuggestions: true,
schema: [],
messages,
},
};

@@ -155,3 +155,3 @@ 'use strict';

// But can't reproduce, just ignore this case
/* istanbul ignore next */
/* c8 ignore next 3 */
if (!variable) {

@@ -158,0 +158,0 @@ return;

@@ -197,3 +197,3 @@ 'use strict';

/* istanbul ignore next */
/* c8 ignore next 3 */
if (variables.length !== 1) {

@@ -200,0 +200,0 @@ return false;

@@ -70,3 +70,3 @@ 'use strict';

/* istanbul ignore else */
/* c8 ignore next 3 */
if (level === 0) {

@@ -73,0 +73,0 @@ return current;

@@ -78,3 +78,3 @@ 'use strict';

const isIncludesCall = node => {
/* istanbul ignore next */
/* c8 ignore next 3 */
if (!node.parent || !node.parent.parent) {

@@ -135,3 +135,3 @@ return false;

// But can't reproduce, just ignore this case
/* istanbul ignore next */
/* c8 ignore next 3 */
if (!variable) {

@@ -138,0 +138,0 @@ return;

@@ -25,3 +25,3 @@ 'use strict';

function getNodeBody(node) {
/* istanbul ignore next */
/* c8 ignore next 3 */
if (!node) {

@@ -28,0 +28,0 @@ return;

@@ -17,6 +17,7 @@ 'use strict';

// We might need this later
/* istanbul ignore next */
/* c8 ignore start */
const isNotDomNode = node =>
impossibleNodeTypes.includes(node.type)
|| (node.type === 'Identifier' && node.name === 'undefined');
/* c8 ignore end */

@@ -23,0 +24,0 @@ const notDomNodeSelector = node => [

@@ -19,3 +19,2 @@ 'use strict';

replacedBy: Array.isArray(replacedBy) ? replacedBy : [replacedBy],
schema: [],
},

@@ -22,0 +21,0 @@ },

@@ -6,3 +6,3 @@ 'use strict';

const eslintVersion = require('eslint/package.json').version;
/* istanbul ignore next */
/* c8 ignore next 3 */
if (eslintVersion.startsWith('7.')) {

@@ -9,0 +9,0 @@ return require(`eslint/lib/rules/${id}`);

@@ -10,3 +10,4 @@ 'use strict';

/* istanbul ignore next: It could be `PrivateIdentifier`(ESTree) or `PrivateName`(Babel) when it's in `class` */
// It could be `PrivateIdentifier`(ESTree) or `PrivateName`(Babel) when it's in `class`
/* c8 ignore next */
return;

@@ -13,0 +14,0 @@ }

'use strict';
const {uniq} = require('lodash');
const getScopes = require('./get-scopes.js');
const getReferences = scope => uniq(
const getReferences = scope => [...new Set(
getScopes(scope).flatMap(({references}) => references),
);
)];
module.exports = getReferences;
'use strict';
const {uniq} = require('lodash');
// Get identifiers of given variable
module.exports = ({identifiers, references}) => uniq([
module.exports = ({identifiers, references}) => [...new Set([
...identifiers,
...references.map(({identifier}) => identifier),
]);
])];

@@ -17,3 +17,3 @@ 'use strict';

function isFunctionSelfUsedInside(functionNode, functionScope) {
/* istanbul ignore next */
/* c8 ignore next 3 */
if (functionScope.block !== functionNode) {

@@ -20,0 +20,0 @@ throw new Error('"functionScope" should be the scope of "functionNode".');

@@ -44,12 +44,12 @@ 'use strict';

/* istanbul ignore next: Hard to test */
/* c8 ignore next 2 */
case 'ChainExpression':
return getStaticPropertyName(node.expression);
/* istanbul ignore next: Only reachable when use this to get class/object member key */
// Only reachable when use this to get class/object member key
/* c8 ignore next */
case 'Property':
case 'MethodDefinition':
/* istanbul ignore next */
/* c8 ignore next 2 */
property = node.key;
/* istanbul ignore next */
break;

@@ -56,0 +56,0 @@

@@ -27,3 +27,3 @@ 'use strict';

/* istanbul ignore next: Safe */
/* c8 ignore next */
throw error;

@@ -30,0 +30,0 @@ }

@@ -10,3 +10,4 @@ 'use strict';

function shouldAddParenthesesToLogicalExpressionChild(node, {operator, property}) {
/* istanbul ignore next: When operator or property is different, need check `LogicalExpression` operator precedence, not implemented */
// When operator or property is different, need check `LogicalExpression` operator precedence, not implemented
/* c8 ignore next 3 */
if (operator !== '??' || property !== 'left') {

@@ -13,0 +14,0 @@ throw new Error('Not supported.');

@@ -29,3 +29,3 @@ 'use strict';

case 'Literal': {
/* istanbul ignore next */
/* c8 ignore next */
if (isDecimalIntegerNode(node)) {

@@ -32,0 +32,0 @@ return true;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc