Skip to content

Commit

Permalink
[eslint] cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Apr 27, 2023
1 parent bc87bcd commit c18a236
Show file tree
Hide file tree
Showing 7 changed files with 190 additions and 296 deletions.
18 changes: 18 additions & 0 deletions .eslintrc
@@ -0,0 +1,18 @@
{
"root": true,

"extends": "@ljharb/eslint-config/node/6",

"overrides": [
{
"files": "test/**/*.js",
"env": {
"mocha": true,
},
"rules": {
"max-lines-per-function": "warn",
"max-nested-callbacks": "warn",
},
},
],
}
130 changes: 0 additions & 130 deletions .eslintrc.json

This file was deleted.

14 changes: 7 additions & 7 deletions README.md
Expand Up @@ -84,11 +84,11 @@ A descriptor may have additional _invalid_ properties (an error will **not** be
var foo = {};

Object.defineProperty(foo, 'bar', {
enumerable: true,
whatever: 'blah', // invalid, but doesn't cause an error
get: function() {
return 'baz';
}
enumerable: true,
whatever: 'blah', // invalid, but doesn't cause an error
get: function() {
return 'baz';
}
});

console.log(foo.bar);
Expand Down Expand Up @@ -139,7 +139,7 @@ You might also be interested in these projects:

### Contributors

| **Commits** | **Contributor** |
| **Commits** | **Contributor** |
| --- | --- |
| 21 | [jonschlinkert](https://github.com/jonschlinkert) |
| 2 | [realityking](https://github.com/realityking) |
Expand All @@ -158,4 +158,4 @@ Released under the [MIT License](LICENSE).

***

_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on November 01, 2017._
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on November 01, 2017._
44 changes: 23 additions & 21 deletions index.js
@@ -1,29 +1,31 @@
'use strict';

const hasOwn = (obj, key) => Object.prototype.hasOwnProperty.call(obj, key);
const isObject = val => {
return val !== null && typeof val === 'object' && !Array.isArray(val);
};
const isObject = (val) => val !== null && typeof val === 'object' && !Array.isArray(val);

const isDescriptor = (obj, key) => {
if (!isObject(obj)) return false;
let desc = key ? Object.getOwnPropertyDescriptor(obj, key) : obj;
if (isObject(desc)) {
let booleans = ['configurable', 'enumerable', 'writable'];
if (!hasOwn(desc, 'value') || hasOwn(desc, 'get') || hasOwn(desc, 'set')) {
return false;
}
for (let key of Object.keys(desc)) {
if (booleans.includes(key) && typeof desc[key] !== 'boolean') {
return false;
}
if (!booleans.includes(key) && key !== 'value') {
return false;
}
}
return true;
}
return false;
if (!isObject(obj)) {
return false;
}
const desc = key ? Object.getOwnPropertyDescriptor(obj, key) : obj;
if (isObject(desc)) {
const booleans = [
'configurable', 'enumerable', 'writable',
];
if (!hasOwn(desc, 'value') || hasOwn(desc, 'get') || hasOwn(desc, 'set')) {
return false;
}
for (const descKey of Object.keys(desc)) {
if (booleans.includes(descKey) && typeof desc[descKey] !== 'boolean') {
return false;
}
if (!booleans.includes(descKey) && descKey !== 'value') {
return false;
}
}
return true;
}
return false;
};

module.exports = isDescriptor;
138 changes: 71 additions & 67 deletions package.json
@@ -1,69 +1,73 @@
{
"name": "is-data-descriptor",
"description": "Returns true if a value has the characteristics of a valid JavaScript data descriptor.",
"version": "2.0.0",
"homepage": "https://github.com/jonschlinkert/is-data-descriptor",
"author": "Jon Schlinkert (https://github.com/jonschlinkert)",
"contributors": [
"Jon Schlinkert (http://twitter.com/jonschlinkert)",
"Rouven Weßling (www.rouvenwessling.de)"
],
"repository": "jonschlinkert/is-data-descriptor",
"bugs": {
"url": "https://github.com/jonschlinkert/is-data-descriptor/issues"
},
"license": "MIT",
"files": [
"index.js"
],
"main": "index.js",
"engines": {
"node": ">=6"
},
"scripts": {
"test": "mocha"
},
"devDependencies": {
"gulp-format-md": "^1.0.0",
"mocha": "^3.5.3"
},
"keywords": [
"accessor",
"check",
"data",
"descriptor",
"get",
"getter",
"is",
"keys",
"object",
"properties",
"property",
"set",
"setter",
"type",
"valid",
"value"
],
"verb": {
"toc": false,
"layout": "default",
"tasks": [
"readme"
],
"plugins": [
"gulp-format-md"
],
"related": {
"list": [
"is-accessor-descriptor",
"is-data-descriptor",
"is-descriptor",
"isobject"
]
},
"lint": {
"reflinks": true
}
}
"name": "is-data-descriptor",
"description": "Returns true if a value has the characteristics of a valid JavaScript data descriptor.",
"version": "2.0.0",
"homepage": "https://github.com/jonschlinkert/is-data-descriptor",
"author": "Jon Schlinkert (https://github.com/jonschlinkert)",
"contributors": [
"Jon Schlinkert (http://twitter.com/jonschlinkert)",
"Rouven Weßling (www.rouvenwessling.de)"
],
"repository": "jonschlinkert/is-data-descriptor",
"bugs": {
"url": "https://github.com/jonschlinkert/is-data-descriptor/issues"
},
"license": "MIT",
"files": [
"index.js"
],
"main": "index.js",
"engines": {
"node": ">=6"
},
"scripts": {
"lint": "eslint --ext=js,mjs .",
"pretest": "npm run lint",
"test": "mocha"
},
"devDependencies": {
"@ljharb/eslint-config": "^21.0.1",
"eslint": "=8.8.0",
"gulp-format-md": "^1.0.0",
"mocha": "^3.5.3"
},
"keywords": [
"accessor",
"check",
"data",
"descriptor",
"get",
"getter",
"is",
"keys",
"object",
"properties",
"property",
"set",
"setter",
"type",
"valid",
"value"
],
"verb": {
"toc": false,
"layout": "default",
"tasks": [
"readme"
],
"plugins": [
"gulp-format-md"
],
"related": {
"list": [
"is-accessor-descriptor",
"is-data-descriptor",
"is-descriptor",
"isobject"
]
},
"lint": {
"reflinks": true
}
}
}

0 comments on commit c18a236

Please sign in to comment.