Socket
Socket
Sign inDemoInstall

eslint-plugin-unicorn

Package Overview
Dependencies
Maintainers
1
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 9.1.1 to 10.0.0

rules/no-keyword-prefix.js

1

index.js

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

'unicorn/no-hex-escape': 'error',
'unicorn/no-keyword-prefix': 'off',
'unicorn/no-new-buffer': 'error',

@@ -36,0 +37,0 @@ 'unicorn/no-process-exit': 'error',

30

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

@@ -35,25 +35,25 @@ "license": "MIT",

"clean-regexp": "^1.0.0",
"eslint-ast-utils": "^1.0.0",
"eslint-ast-utils": "^1.1.0",
"import-modules": "^1.1.0",
"lodash.camelcase": "^4.1.1",
"lodash.camelcase": "^4.3.0",
"lodash.defaultsdeep": "^4.6.0",
"lodash.kebabcase": "^4.0.1",
"lodash.snakecase": "^4.0.1",
"lodash.kebabcase": "^4.1.1",
"lodash.snakecase": "^4.1.1",
"lodash.topairs": "^4.3.0",
"lodash.upperfirst": "^4.2.0",
"lodash.upperfirst": "^4.3.1",
"regexpp": "^2.0.1",
"reserved-words": "^0.1.2",
"safe-regex": "^2.0.1"
"safe-regex": "^2.0.2"
},
"devDependencies": {
"ava": "^1.4.1",
"babel-eslint": "^10.0.0",
"ava": "^2.1.0",
"babel-eslint": "^10.0.2",
"chalk": "^2.4.2",
"coveralls": "^3.0.0",
"del": "^4.1.1",
"eslint": "^5.12.0",
"coveralls": "^3.0.4",
"del": "^5.0.0",
"eslint": "^6.0.1",
"eslint-ava-rule-tester": "^3.0.0",
"eslint-plugin-eslint-plugin": "2.1.0",
"execa": "^1.0.0",
"listr": "^0.14.1",
"execa": "^2.0.3",
"listr": "^0.14.3",
"nyc": "^14.1.1",

@@ -66,3 +66,3 @@ "outdent": "^0.7.0",

"peerDependencies": {
"eslint": ">=5.0.0"
"eslint": ">=6.0.0"
},

@@ -69,0 +69,0 @@ "ava": {

@@ -52,2 +52,3 @@ # 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/no-keyword-prefix": "off",
"unicorn/no-new-buffer": "error",

@@ -97,2 +98,3 @@ "unicorn/no-process-exit": "error",

- [no-hex-escape](docs/rules/no-hex-escape.md) - Enforce the use of Unicode escapes instead of hexadecimal escapes. *(fixable)*
- [no-keyword-prefix](docs/rules/no-keyword-prefix.md) - Disallow identifiers starting with `new` or `class`.
- [no-new-buffer](docs/rules/no-new-buffer.md) - Enforce the use of `Buffer.from()` and `Buffer.alloc()` instead of the deprecated `new Buffer()`. *(fixable)*

@@ -99,0 +101,0 @@ - [no-process-exit](docs/rules/no-process-exit.md) - Disallow `process.exit()`.

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

if (filenameWithExtension === '<text>') {
if (filenameWithExtension === '<input>') {
return {};

@@ -120,0 +120,0 @@ }

@@ -17,11 +17,10 @@ 'use strict';

context.report({
// Can't set it at the given location as the warning
// will be ignored due to the disable comment
loc: {
line: 0,
column: 0
start: {
...comment.loc.start,
column: -1
},
end: comment.loc.end
},
// So specify the location in the message
message: 'Specify the rules you want to disable at line {{line}}:{{column}}',
data: comment.loc.start
message: 'Specify the rules you want to disable.'
});

@@ -28,0 +27,0 @@ }

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

[selector]: node => {
if (isIteratorMethod(node) && hasFunctionArgument(node)) {
if (isIteratorMethod(node) && hasFunctionArgument(node) && node.arguments.length <= getNumberOfArguments(node)) {
const [arg] = node.arguments;

@@ -55,0 +55,0 @@

@@ -284,2 +284,6 @@ 'use strict';

if (!bodyScope) {
return;
}
const indexVariable = resolveIdentifierName(indexIdentifierName, bodyScope);

@@ -286,0 +290,0 @@

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

221: ']',
222: '\'',
222: '\\\'',
224: 'Meta'

@@ -60,0 +60,0 @@ };

@@ -25,6 +25,4 @@ 'use strict';

return text;
case 'UnaryExpression':
return text;
default:
// Handle cases like Math.pow(2, 2-1);
// Handle cases like Math.pow(-0, 2-1);
return `(${text})`;

@@ -31,0 +29,0 @@ }

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

const MESSAGE_ID = 'preferFlatMap';
const MESSAGE_ID_FLATMAP = 'flat-map';
const MESSAGE_ID_SPREAD = 'spread';
const report = (context, nodeFlat, nodeMap) => {
const SELECTOR_SPREAD = [
// [].concat(...bar.map((i) => i))
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'CallExpression',
// [].concat(...bar.map((i) => i))
// ^^
'[callee.object.type="ArrayExpression"]',
'[callee.object.elements.length=0]',
// [].concat(...bar.map((i) => i))
// ^^^^^^
'[callee.property.name="concat"]',
// [].concat(...bar.map((i) => i))
// ^^^^^^^^^^^^^^^^^^^^
'[arguments.0.type="SpreadElement"]',
// [].concat(...bar.map((i) => i))
// ^^^
'[arguments.0.argument.callee.property.name="map"]'
].join('');
const reportFlatMap = (context, nodeFlat, nodeMap) => {
const source = context.getSourceCode();

@@ -63,3 +87,3 @@

node: nodeFlat,
messageId: MESSAGE_ID,
messageId: MESSAGE_ID_FLATMAP,
fix: fixer => {

@@ -117,3 +141,9 @@ const fixings = [

report(context, node, parent);
reportFlatMap(context, node, parent);
},
[SELECTOR_SPREAD]: node => {
context.report({
node,
messageId: MESSAGE_ID_SPREAD
});
}

@@ -131,5 +161,6 @@ });

messages: {
[MESSAGE_ID]: 'Prefer `.flatMap(…)` over `.map(…).flat()`.'
[MESSAGE_ID_FLATMAP]: 'Prefer `.flatMap(…)` over `.map(…).flat()`.',
[MESSAGE_ID_SPREAD]: 'Prefer `.flatMap(…)` over `[].concat(...foo.map(…))`.'
}
}
};
'use strict';
const path = require('path');
const astUtils = require('eslint-ast-utils');

@@ -8,2 +9,3 @@ const defaultsDeep = require('lodash.defaultsdeep');

const upperfirst = require('lodash.upperfirst');
const snakeCase = require('lodash.snakecase');

@@ -182,2 +184,12 @@ const getDocsUrl = require('./utils/get-docs-url');

const getCase = string => {
for (const fn of [camelCase, kebabCase, snakeCase, upperfirst]) {
if (string === fn(string)) {
return fn;
}
}
return camelCase;
};
const prepareOptions = ({

@@ -191,2 +203,4 @@ checkProperties = true,

checkFilenames = true,
extendDefaultReplacements = true,

@@ -214,2 +228,4 @@ replacements = {},

checkFilenames,
replacements: new Map(toPairs(mergedReplacements).map(([discouragedName, replacements]) => {

@@ -540,2 +556,3 @@ return [discouragedName, new Map(toPairs(replacements))];

const options = prepareOptions(context.options[0]);
const filenameWithExtension = context.getFilename();

@@ -686,2 +703,32 @@ // A `class` declaration produces two variables in two scopes:

Program(node) {
if (!options.checkFilenames) {
return;
}
if (filenameWithExtension === '<input>') {
return {};
}
const extension = path.extname(filenameWithExtension);
const filename = path.basename(filenameWithExtension, extension);
const originalCase = getCase(filename);
const filenameReplacements = getNameReplacements(
options.replacements,
options.whitelist,
filename
)
.map(replacement => `${originalCase(replacement)}${extension}`);
if (filenameReplacements.length === 0) {
return;
}
context.report({
node,
message: formatMessage(filenameWithExtension, filenameReplacements, 'file')
});
},
'Program:exit'() {

@@ -707,2 +754,4 @@ if (!options.checkVariables) {

checkFilenames: {type: 'boolean'},
extendDefaultReplacements: {type: 'boolean'},

@@ -709,0 +758,0 @@ replacements: {$ref: '#/items/0/definitions/abbreviations'},

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

// Escape backslash and apostrophe because we wrap the result in single quotes
fixed = (newPattern || '').replace(/\\/, '\\\\');
fixed = fixed.replace(/'/, '\'');
fixed = (newPattern || '').replace(/\\/g, '\\\\');
fixed = fixed.replace(/'/g, '\\\'');
fixed = `'${fixed}'`;

@@ -59,0 +59,0 @@ }

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