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 14.0.1 to 15.0.0

rules/prefer-modern-dom-apis.js

1

index.js

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

'unicorn/prefer-includes': 'error',
'unicorn/prefer-modern-dom-apis': 'error',
'unicorn/prefer-negative-index': 'error',

@@ -54,0 +55,0 @@ 'unicorn/prefer-node-append': 'error',

18

package.json
{
"name": "eslint-plugin-unicorn",
"version": "14.0.1",
"version": "15.0.0",
"description": "Various awesome ESLint rules",
"license": "MIT",
"repository": "sindresorhus/eslint-plugin-unicorn",
"funding": "https://github.com/sindresorhus/eslint-plugin-unicorn?sponsor=1",
"author": {

@@ -44,14 +45,13 @@ "name": "Sindre Sorhus",

"lodash.snakecase": "^4.1.1",
"lodash.topairs": "^4.3.0",
"lodash.upperfirst": "^4.3.1",
"read-pkg-up": "^7.0.0",
"regexp-tree": "^0.1.16",
"read-pkg-up": "^7.0.1",
"regexp-tree": "^0.1.17",
"regexpp": "^3.0.0",
"reserved-words": "^0.1.2",
"safe-regex": "^2.1.1",
"semver": "^6.3.0"
"semver": "^7.1.1"
},
"devDependencies": {
"@lubien/fixture-beta-package": "^1.0.0-beta.1",
"@typescript-eslint/parser": "^2.9.0",
"@typescript-eslint/parser": "^2.12.0",
"ava": "^2.4.0",

@@ -62,6 +62,6 @@ "babel-eslint": "^10.0.3",

"del": "^5.1.0",
"eslint": "^6.6.0",
"eslint": "^6.8.0",
"eslint-ava-rule-tester": "^4.0.0",
"eslint-plugin-eslint-plugin": "2.1.0",
"execa": "^3.4.0",
"execa": "^4.0.0",
"listr": "^0.14.3",

@@ -72,3 +72,3 @@ "nyc": "^14.1.1",

"tempy": "^0.3.0",
"typescript": "^3.7.2",
"typescript": "^3.7.4",
"xo": "^0.25.3"

@@ -75,0 +75,0 @@ },

@@ -14,3 +14,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)

```
```console
$ npm install --save-dev eslint eslint-plugin-unicorn

@@ -71,2 +71,3 @@ ```

"unicorn/prefer-includes": "error",
"unicorn/prefer-modern-dom-apis": "error",
"unicorn/prefer-negative-index": "error",

@@ -125,2 +126,3 @@ "unicorn/prefer-node-append": "error",

- [prefer-includes](docs/rules/prefer-includes.md) - Prefer `.includes()` over `.indexOf()` when checking for existence or non-existence. *(fixable)*
- [prefer-modern-dom-apis](docs/rules/prefer-modern-dom-apis.md) - Prefer `.before()` over `.insertBefore()`, `.replaceWith()` over `.replaceChild()`, prefer one of `.before()`, `.after()`, `.append()` or `.prepend()` over `insertAdjacentText()` and `insertAdjacentElement()`. *(fixable)*
- [prefer-negative-index](docs/rules/prefer-negative-index.md) - Prefer negative index over `.length - index` for `{String,Array,TypedArray}#slice()` and `Array#splice()`. *(fixable)*

@@ -127,0 +129,0 @@ - [prefer-node-append](docs/rules/prefer-node-append.md) - Prefer `Node#append()` over `Node#appendChild()`. *(fixable)*

@@ -332,5 +332,20 @@ 'use strict';

let declarationElement = element;
let declarationType = 'const';
let removeDeclaration = true;
if (
elementNode &&
elementNode.id.type === 'ObjectPattern'
) {
removeDeclaration = arrayReferences.length === 1;
if (removeDeclaration) {
declarationType = elementNode.parent.kind;
declarationElement = sourceCode.getText(elementNode.id);
}
}
const replacement = shouldGenerateIndex ?
`const [${index}, ${element}] of ${array}.entries()` :
`const ${element} of ${array}`;
`${declarationType} [${index}, ${declarationElement}] of ${array}.entries()` :
`${declarationType} ${declarationElement} of ${array}`;

@@ -349,3 +364,7 @@ return [

}),
elementNode && fixer.removeRange(getRemovalRange(elementNode, sourceCode))
elementNode && (
removeDeclaration ?
fixer.removeRange(getRemovalRange(elementNode, sourceCode)) :
fixer.replaceText(elementNode.init, element)
)
].filter(Boolean);

@@ -352,0 +371,0 @@ };

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

const defaultsDeep = require('lodash.defaultsdeep');
const toPairs = require('lodash.topairs');

@@ -17,29 +16,65 @@ const getDocumentationUrl = require('./utils/get-documentation-url');

// Keep this alphabetically sorted for easier maintenance
const defaultReplacements = {
err: {
error: true
acc: {
accumulator: true
},
arg: {
argument: true
},
args: {
arguments: true
},
arr: {
array: true
},
attr: {
attribute: true
},
attrs: {
attributes: true
},
btn: {
button: true
},
cb: {
callback: true
},
opts: {
options: true
conf: {
config: true
},
str: {
string: true
ctx: {
context: true
},
obj: {
object: true
cur: {
current: true
},
num: {
number: true
curr: {
current: true
},
val: {
value: true
db: {
database: true
},
dest: {
destination: true
},
dev: {
development: true
},
dir: {
direction: true,
directory: true
},
dirs: {
directories: true
},
doc: {
document: true
},
docs: {
documentation: true,
documents: true
},
e: {
event: true,
error: true
},
evt: {
error: true,
event: true

@@ -50,35 +85,43 @@ },

},
req: {
request: true
elem: {
element: true
},
res: {
response: true,
result: true
env: {
environment: true
},
btn: {
button: true
envs: {
environments: true
},
msg: {
message: true
err: {
error: true
},
evt: {
event: true
},
ext: {
extension: true
},
exts: {
extensions: true
},
len: {
length: true
},
env: {
environment: true
lib: {
library: true
},
dev: {
development: true
mod: {
module: true
},
prod: {
production: true
msg: {
message: true
},
tmp: {
temporary: true
num: {
number: true
},
arg: {
argument: true
obj: {
object: true
},
args: {
arguments: true
opts: {
options: true
},

@@ -91,42 +134,17 @@ param: {

},
tbl: {
table: true
pkg: {
package: true
},
db: {
database: true
prev: {
previous: true
},
ctx: {
context: true
prod: {
production: true
},
mod: {
module: true
},
prop: {
property: true
},
arr: {
array: true
props: {
properties: true
},
ret: {
returnValue: true
},
retval: {
returnValue: true
},
ext: {
extension: true
},
exts: {
extensions: true
},
lib: {
library: true
},
dir: {
directory: true,
direction: true
},
dirs: {
directories: true
},
ref: {

@@ -138,55 +156,46 @@ reference: true

},
pkg: {
package: true
rel: {
related: true,
relationship: true,
relative: true
},
sep: {
separator: true
req: {
request: true
},
doc: {
document: true
res: {
response: true,
result: true
},
docs: {
documents: true,
documentation: true
ret: {
returnValue: true
},
elem: {
element: true
retval: {
returnValue: true
},
sep: {
separator: true
},
src: {
source: true
},
dest: {
destination: true
stdDev: {
standardDeviation: true
},
prev: {
previous: true
str: {
string: true
},
curr: {
current: true
tbl: {
table: true
},
cur: {
current: true
},
acc: {
accumulator: true
},
rel: {
relative: true,
related: true,
relationship: true
},
conf: {
config: true
},
temp: {
temporary: true
},
props: {
properties: true
tit: {
title: true
},
attr: {
attribute: true
tmp: {
temporary: true
},
attrs: {
attributes: true
val: {
value: true
}

@@ -196,6 +205,23 @@ };

const defaultWhitelist = {
// React PropTypes
// https://reactjs.org/docs/typechecking-with-proptypes.html
propTypes: true,
// React.Component Class property
// https://reactjs.org/docs/react-component.html#defaultprops
defaultProps: true,
// React.Component static method
// https://reactjs.org/docs/react-component.html#static-getderivedstatefromprops
getDerivedStateFromProps: true,
stdDev: true
// Ember class name
// https://api.emberjs.com/ember/3.10/classes/Ember.EmberENV/properties
EmberENV: true,
// `package.json` field
// https://docs.npmjs.com/specifying-dependencies-and-devdependencies-in-a-package-json-file
devDependencies: true,
// Jest configuration
// https://jestjs.io/docs/en/configuration#setupfilesafterenv-array
setupFilesAfterEnv: true,
// Next.js function
// https://nextjs.org/learn/basics/fetching-data-for-pages
getInitialProps: true
};

@@ -237,6 +263,9 @@

replacements: new Map(toPairs(mergedReplacements).map(([discouragedName, replacements]) => {
return [discouragedName, new Map(toPairs(replacements))];
})),
whitelist: new Map(toPairs(mergedWhitelist))
replacements: new Map(
Object.entries(mergedReplacements).map(
([discouragedName, replacements]) =>
[discouragedName, new Map(Object.entries(replacements))]
)
),
whitelist: new Map(Object.entries(mergedWhitelist))
};

@@ -341,7 +370,8 @@ };

const variableIdentifiers = variable => [...(new Set([
...variable.identifiers,
...variable.references
.map(reference => reference.identifier)
])).values()];
const variableIdentifiers = ({identifiers, references}) => [
...new Set([
...identifiers,
...references.map(({identifier}) => identifier)
])
];

@@ -348,0 +378,0 @@ const isExportedIdentifier = identifier => {

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