Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

eslint-plugin-unicorn

Package Overview
Dependencies
Maintainers
3
Versions
106
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 3.0.1 to 4.0.0

rules/error-message.js

12

index.js

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

parserOptions: {
ecmaVersion: 2017,
ecmaVersion: 2018,
sourceType: 'module'

@@ -29,9 +29,13 @@ },

'unicorn/no-hex-escape': 'error',
'unicorn/custom-error-definition': 'error',
'unicorn/custom-error-definition': 'off',
'unicorn/prefer-starts-ends-with': 'error',
'unicorn/prefer-type-error': 'error',
'unicorn/no-fn-reference-in-iterator': 'error',
'unicorn/no-fn-reference-in-iterator': 'off',
'unicorn/import-index': 'error',
'unicorn/new-for-builtins': 'error',
'unicorn/regex-shorthand': 'error'
'unicorn/regex-shorthand': 'error',
'unicorn/prefer-spread': 'error',
'unicorn/error-message': 'error',
'unicorn/no-unsafe-regex': 'error',
'unicorn/prefer-add-event-listener': 'error'
}

@@ -38,0 +42,0 @@ }

{
"name": "eslint-plugin-unicorn",
"version": "3.0.1",
"version": "4.0.0",
"description": "Various awesome ESLint rules",

@@ -12,19 +12,2 @@ "license": "MIT",

},
"maintainers": [
{
"name": "James Talmage",
"email": "james@talmage.io",
"url": "github.com/jamestalmage"
},
{
"name": "Jeroen Engels",
"email": "jfm.engels@gmail.com",
"url": "github.com/jfmengels"
},
{
"name": "Sam Verschueren",
"email": "sam.verschueren@gmail.com",
"url": "github.com/SamVerschueren"
}
],
"engines": {

@@ -59,3 +42,4 @@ "node": ">=4"

"lodash.snakecase": "^4.0.1",
"lodash.upperfirst": "^4.2.0"
"lodash.upperfirst": "^4.2.0",
"safe-regex": "^1.1.0"
},

@@ -69,3 +53,3 @@ "devDependencies": {

"eslint-ava-rule-tester": "^2.0.0",
"execa": "^0.8.0",
"execa": "^0.9.0",
"listr": "^0.13.0",

@@ -72,0 +56,0 @@ "nyc": "^11.0.3",

@@ -47,9 +47,13 @@ # eslint-plugin-unicorn [![Build Status](https://travis-ci.org/sindresorhus/eslint-plugin-unicorn.svg?branch=master)](https://travis-ci.org/sindresorhus/eslint-plugin-unicorn) [![Coverage Status](https://coveralls.io/repos/github/sindresorhus/eslint-plugin-unicorn/badge.svg?branch=master)](https://coveralls.io/github/sindresorhus/eslint-plugin-unicorn?branch=master)

"unicorn/no-hex-escape": "error",
"unicorn/custom-error-definition": "error",
"unicorn/custom-error-definition": "off",
"unicorn/prefer-starts-ends-with": "error",
"unicorn/prefer-type-error": "error",
"unicorn/no-fn-reference-in-iterator": "error",
"unicorn/no-fn-reference-in-iterator": "off",
"unicorn/import-index": "error",
"unicorn/new-for-builtins": "error",
"unicorn/regex-shorthand": "error"
"unicorn/regex-shorthand": "error",
"unicorn/prefer-spread": "error",
"unicorn/error-message": "error",
"unicorn/no-unsafe-regex": "error",
"unicorn/prefer-add-event-listener": "error"
}

@@ -81,2 +85,6 @@ }

- [regex-shorthand](docs/rules/regex-shorthand.md) - Enforce the use of regex shorthands to improve readability. *(fixable)*
- [prefer-spread](docs/rules/prefer-spread.md) - Prefer the spread operator over `Array.from()`. *(fixable)*
- [error-message](docs/rules/error-message.md) - Enforce passing a `message` value when throwing a built-in error.
- [no-unsafe-regex](docs/rules/no-unsafe-regex.md) - Disallow unsafe regular expressions.
- [prefer-add-event-listener](docs/rules/prefer-add-event-listener.md) - Prefer `addEventListener` over `on`-functions. *(fixable)*

@@ -107,3 +115,3 @@

## Created by
## Maintainers

@@ -114,3 +122,3 @@ - [Sindre Sorhus](https://github.com/sindresorhus)

- [Sam Verschueren](https://github.com/SamVerschueren)
- [Contributors…](../../graphs/contributors)
- [John Wu](https://github.com/johnwu93)

@@ -120,2 +128,2 @@

MIT © [Sindre Sorhus](https://sindresorhus.com)
MIT
'use strict';
const astUtils = require('eslint-ast-utils');
const getDocsUrl = require('./utils/get-docs-url');
// Matches someObj.then([FunctionExpression | ArrowFunctionExpression])
// Matches `someObj.then([FunctionExpression | ArrowFunctionExpression])`
function isLintablePromiseCatch(node) {

@@ -39,4 +40,9 @@ const callee = node.callee;

const create = context => {
const opts = context.options[0];
const name = (opts && opts.name) || 'err';
const options = Object.assign({}, {
name: 'err',
caughtErrorsIgnorePattern: '^_$'
}, context.options[0]);
const name = options.name;
const caughtErrorsIgnorePattern = new RegExp(options.caughtErrorsIgnorePattern);
const stack = [];

@@ -55,3 +61,3 @@

if (value !== true) {
if (value !== true && !caughtErrorsIgnorePattern.test(node.name)) {
context.report({

@@ -103,2 +109,5 @@ node,

type: 'string'
},
caughtErrorsIgnorePattern: {
type: 'string'
}

@@ -111,4 +120,7 @@ }

meta: {
docs: {
url: getDocsUrl()
},
schema
}
};
'use strict';
const upperfirst = require('lodash.upperfirst');
const getDocsUrl = require('./utils/get-docs-url');
const nameRegexp = /^(?:[A-Z][a-z0-9]*)*Error$/;
const nameRegexp = /^(?:[A-Z][a-z\d]*)*Error$/;

@@ -133,4 +134,7 @@ const getClassName = name => upperfirst(name).replace(/(error|)$/i, 'Error');

meta: {
docs: {
url: getDocsUrl()
},
fixable: 'code'
}
};
'use strict';
const getDocsUrl = require('./utils/get-docs-url');
const escapeWithLowercase = /((?:^|[^\\])(?:\\\\)*)\\(x[a-f\d]{2}|u[a-f\d]{4}|u\{(?:[a-f\d]{1,})\}|c[a-z])/;

@@ -56,4 +58,7 @@ const hasLowercaseCharacter = /[a-z]+/;

meta: {
docs: {
url: getDocsUrl()
},
fixable: 'code'
}
};
'use strict';
const getDocsUrl = require('./utils/get-docs-url');

@@ -150,2 +151,5 @@ const operatorTypes = {

meta: {
docs: {
url: getDocsUrl()
},
fixable: 'code',

@@ -152,0 +156,0 @@ schema

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

const upperfirst = require('lodash.upperfirst');
const getDocsUrl = require('./utils/get-docs-url');

@@ -82,2 +83,7 @@ const pascalCase = str => upperfirst(camelCase(str));

const filename = path.basename(filenameWithExt, extension);
if (filename + extension === 'index.js') {
return;
}
const splitName = splitFilename(filename);

@@ -114,4 +120,7 @@ const fixedFilename = fixFilename(chosenCase, splitName.trailing);

meta: {
docs: {
url: getDocsUrl()
},
schema
}
};
'use strict';
const getDocsUrl = require('./utils/get-docs-url');
const regexp = /^(@.*?\/.*?|[./]+?.*?)(?:\/(?:index(?:\.js)?)?)$/;

@@ -26,4 +28,7 @@ const isImportingIndex = m => regexp.test(m);

meta: {
docs: {
url: getDocsUrl()
},
fixable: 'code'
}
};
'use strict';
const getDocsUrl = require('./utils/get-docs-url');
const enforceNew = new Set([

@@ -67,4 +69,7 @@ 'Object',

meta: {
docs: {
url: getDocsUrl()
},
fixable: 'code'
}
};
'use strict';
const getDocsUrl = require('./utils/get-docs-url');
const disableRegex = /^eslint-disable(-next-line|-line)?($|(\s+([\w-]+))?)/;
const disableRegex = /^eslint-disable(-next-line|-line)?($|(\s+(@[\w-]+\/[\w-]+\/)?[\w-]+)?)/;

@@ -32,3 +33,7 @@ const create = context => ({

create,
meta: {}
meta: {
docs: {
url: getDocsUrl()
}
}
};
'use strict';
const getDocsUrl = require('./utils/get-docs-url');

@@ -21,4 +22,7 @@ const create = context => ({

meta: {
docs: {
url: getDocsUrl()
},
fixable: 'code'
}
};
'use strict';
const getDocsUrl = require('./utils/get-docs-url');
const iteratorMethods = new Map([

@@ -49,4 +51,7 @@ ['map', 1],

meta: {
docs: {
url: getDocsUrl()
},
fixable: 'code'
}
};
/* eslint-disable unicorn/no-hex-escape */
'use strict';
const getDocsUrl = require('./utils/get-docs-url');

@@ -30,4 +31,7 @@ function checkEscape(context, node, value) {

meta: {
docs: {
url: getDocsUrl()
},
fixable: 'code'
}
};
'use strict';
const getDocsUrl = require('./utils/get-docs-url');
const inferMethod = args => (args.length > 0 && typeof args[0].value === 'number') ? 'alloc' : 'from';

@@ -25,4 +27,7 @@

meta: {
docs: {
url: getDocsUrl()
},
fixable: 'code'
}
};
'use strict';
const getDocsUrl = require('./utils/get-docs-url');

@@ -40,3 +41,7 @@ const create = context => {

create,
meta: {}
meta: {
docs: {
url: getDocsUrl()
}
}
};
'use strict';
const getDocsUrl = require('./utils/get-docs-url');
const fix = value => {

@@ -33,4 +35,7 @@ if (!/^0[a-zA-Z]/.test(value)) {

meta: {
docs: {
url: getDocsUrl()
},
fixable: 'code'
}
};
'use strict';
const getDocsUrl = require('./utils/get-docs-url');
const doesNotContain = (string, chars) => chars.every(char => !string.includes(char));

@@ -52,4 +54,7 @@

create,
meta: {}
meta: {
docs: {
url: getDocsUrl()
}
}
};
'use strict';
const getDocsUrl = require('./utils/get-docs-url');

@@ -121,4 +122,7 @@ const tcIdentifiers = new Set([

meta: {
docs: {
url: getDocsUrl()
},
fixable: 'code'
}
};
'use strict';
const cleanRegexp = require('clean-regexp');
const getDocsUrl = require('./utils/get-docs-url');

@@ -14,2 +15,7 @@ const message = 'Use regex shorthands to improve readability.';

// Handle regex literal inside RegExp constructor in the other handler
if (node.parent.type === 'NewExpression' && node.parent.callee.name === 'RegExp') {
return;
}
if (oldPattern !== newPattern) {

@@ -30,5 +36,15 @@ context.report({

const oldPattern = args[0].value;
const flags = args[1] && args[1].type === 'Literal' ? args[1].value : '';
const hasRegExp = args[0].regex;
let oldPattern = null;
let flags = null;
if (hasRegExp) {
oldPattern = args[0].regex.pattern;
flags = args[1] && args[1].type === 'Literal' ? args[1].value : args[0].regex.flags;
} else {
oldPattern = args[0].value;
flags = args[1] && args[1].type === 'Literal' ? args[1].value : '';
}
const newPattern = cleanRegexp(oldPattern, flags);

@@ -40,3 +56,3 @@

message,
fix: fixer => fixer.replaceTextRange(args[0].range, `'${newPattern}'`)
fix: fixer => fixer.replaceTextRange(args[0].range, hasRegExp ? `/${newPattern}/` : `'${newPattern}'`)
});

@@ -51,4 +67,7 @@ }

meta: {
docs: {
url: getDocsUrl()
},
fixable: 'code'
}
};
'use strict';
const getDocsUrl = require('./utils/get-docs-url');
const customError = /^(?:[A-Z][a-z0-9]*)*Error$/;
const customError = /^(?:[A-Z][a-z\d]*)*Error$/;

@@ -23,4 +24,7 @@ const create = context => ({

meta: {
docs: {
url: getDocsUrl()
},
fixable: 'code'
}
};
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