Skip to content

Commit

Permalink
Add @elastic/safer-lodash-set as an alternative to lodash.set (#67452)
Browse files Browse the repository at this point in the history
  • Loading branch information
watson committed Jul 15, 2020
1 parent 42c3efd commit fc5bc6b
Show file tree
Hide file tree
Showing 137 changed files with 2,475 additions and 196 deletions.
231 changes: 228 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,31 @@ const ELASTIC_LICENSE_HEADER = `
*/
`;

const SAFER_LODASH_SET_HEADER = `
/*
* Elasticsearch B.V licenses this file to you under the MIT License.
* See \`packages/elastic-safer-lodash-set/LICENSE\` for more information.
*/
`;

const SAFER_LODASH_SET_LODASH_HEADER = `
/*
* This file is forked from the lodash project (https://lodash.com/),
* and may include modifications made by Elasticsearch B.V.
* Elasticsearch B.V. licenses this file to you under the MIT License.
* See \`packages/elastic-safer-lodash-set/LICENSE\` for more information.
*/
`;

const SAFER_LODASH_SET_DEFINITELYTYPED_HEADER = `
/*
* This file is forked from the DefinitelyTyped project (https://github.com/DefinitelyTyped/DefinitelyTyped),
* and may include modifications made by Elasticsearch B.V.
* Elasticsearch B.V. licenses this file to you under the MIT License.
* See \`packages/elastic-safer-lodash-set/LICENSE\` for more information.
*/
`;

const allMochaRulesOff = {};
Object.keys(require('eslint-plugin-mocha').rules).forEach((k) => {
allMochaRulesOff['mocha/' + k] = 'off';
Expand Down Expand Up @@ -143,7 +168,12 @@ module.exports = {
'@kbn/eslint/disallow-license-headers': [
'error',
{
licenses: [ELASTIC_LICENSE_HEADER],
licenses: [
ELASTIC_LICENSE_HEADER,
SAFER_LODASH_SET_HEADER,
SAFER_LODASH_SET_LODASH_HEADER,
SAFER_LODASH_SET_DEFINITELYTYPED_HEADER,
],
},
],
},
Expand Down Expand Up @@ -174,7 +204,82 @@ module.exports = {
'@kbn/eslint/disallow-license-headers': [
'error',
{
licenses: [APACHE_2_0_LICENSE_HEADER],
licenses: [
APACHE_2_0_LICENSE_HEADER,
SAFER_LODASH_SET_HEADER,
SAFER_LODASH_SET_LODASH_HEADER,
SAFER_LODASH_SET_DEFINITELYTYPED_HEADER,
],
},
],
},
},

/**
* safer-lodash-set package requires special license headers
*/
{
files: ['packages/elastic-safer-lodash-set/**/*.{js,mjs,ts,tsx}'],
rules: {
'@kbn/eslint/require-license-header': [
'error',
{
license: SAFER_LODASH_SET_LODASH_HEADER,
},
],
'@kbn/eslint/disallow-license-headers': [
'error',
{
licenses: [
ELASTIC_LICENSE_HEADER,
APACHE_2_0_LICENSE_HEADER,
SAFER_LODASH_SET_HEADER,
SAFER_LODASH_SET_DEFINITELYTYPED_HEADER,
],
},
],
},
},
{
files: ['packages/elastic-safer-lodash-set/test/*.{js,mjs,ts,tsx}'],
rules: {
'@kbn/eslint/require-license-header': [
'error',
{
license: SAFER_LODASH_SET_HEADER,
},
],
'@kbn/eslint/disallow-license-headers': [
'error',
{
licenses: [
ELASTIC_LICENSE_HEADER,
APACHE_2_0_LICENSE_HEADER,
SAFER_LODASH_SET_LODASH_HEADER,
SAFER_LODASH_SET_DEFINITELYTYPED_HEADER,
],
},
],
},
},
{
files: ['packages/elastic-safer-lodash-set/**/*.d.ts'],
rules: {
'@kbn/eslint/require-license-header': [
'error',
{
license: SAFER_LODASH_SET_DEFINITELYTYPED_HEADER,
},
],
'@kbn/eslint/disallow-license-headers': [
'error',
{
licenses: [
ELASTIC_LICENSE_HEADER,
APACHE_2_0_LICENSE_HEADER,
SAFER_LODASH_SET_HEADER,
SAFER_LODASH_SET_LODASH_HEADER,
],
},
],
},
Expand Down Expand Up @@ -541,9 +646,129 @@ module.exports = {
* Harden specific rules
*/
{
files: ['test/harden/*.js'],
files: ['test/harden/*.js', 'packages/elastic-safer-lodash-set/test/*.js'],
rules: allMochaRulesOff,
},
{
files: ['**/*.{js,mjs,ts,tsx}'],
rules: {
'no-restricted-imports': [
2,
{
paths: [
{
name: 'lodash',
importNames: ['set', 'setWith'],
message: 'Please use @elastic/safer-lodash-set instead',
},
{
name: 'lodash.set',
message: 'Please use @elastic/safer-lodash-set instead',
},
{
name: 'lodash.setwith',
message: 'Please use @elastic/safer-lodash-set instead',
},
{
name: 'lodash/set',
message: 'Please use @elastic/safer-lodash-set instead',
},
{
name: 'lodash/setWith',
message: 'Please use @elastic/safer-lodash-set instead',
},
{
name: 'lodash/fp',
importNames: ['set', 'setWith', 'assoc', 'assocPath'],
message: 'Please use @elastic/safer-lodash-set instead',
},
{
name: 'lodash/fp/set',
message: 'Please use @elastic/safer-lodash-set instead',
},
{
name: 'lodash/fp/setWith',
message: 'Please use @elastic/safer-lodash-set instead',
},
{
name: 'lodash/fp/assoc',
message: 'Please use @elastic/safer-lodash-set instead',
},
{
name: 'lodash/fp/assocPath',
message: 'Please use @elastic/safer-lodash-set instead',
},
],
},
],
'no-restricted-modules': [
2,
{
paths: [
{
name: 'lodash.set',
message: 'Please use @elastic/safer-lodash-set instead',
},
{
name: 'lodash.setwith',
message: 'Please use @elastic/safer-lodash-set instead',
},
{
name: 'lodash/set',
message: 'Please use @elastic/safer-lodash-set instead',
},
{
name: 'lodash/setWith',
message: 'Please use @elastic/safer-lodash-set instead',
},
],
},
],
'no-restricted-properties': [
2,
{
object: 'lodash',
property: 'set',
message: 'Please use @elastic/safer-lodash-set instead',
},
{
object: '_',
property: 'set',
message: 'Please use @elastic/safer-lodash-set instead',
},
{
object: 'lodash',
property: 'setWith',
message: 'Please use @elastic/safer-lodash-set instead',
},
{
object: '_',
property: 'setWith',
message: 'Please use @elastic/safer-lodash-set instead',
},
{
object: 'lodash',
property: 'assoc',
message: 'Please use @elastic/safer-lodash-set instead',
},
{
object: '_',
property: 'assoc',
message: 'Please use @elastic/safer-lodash-set instead',
},
{
object: 'lodash',
property: 'assocPath',
message: 'Please use @elastic/safer-lodash-set instead',
},
{
object: '_',
property: 'assocPath',
message: 'Please use @elastic/safer-lodash-set instead',
},
],
},
},

/**
* APM overrides
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
"@elastic/good": "8.1.1-kibana2",
"@elastic/numeral": "^2.5.0",
"@elastic/request-crypto": "1.1.4",
"@elastic/safer-lodash-set": "0.0.0",
"@elastic/ui-ace": "0.2.3",
"@hapi/good-squeeze": "5.2.1",
"@hapi/wreck": "^15.0.2",
Expand Down
2 changes: 2 additions & 0 deletions packages/elastic-safer-lodash-set/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.tmp
node_modules
3 changes: 3 additions & 0 deletions packages/elastic-safer-lodash-set/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
tsconfig.json
scripts
test
34 changes: 34 additions & 0 deletions packages/elastic-safer-lodash-set/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
The MIT License (MIT)

Copyright (c) Elasticsearch BV
Copyright (c) Brian Zengel <https://github.com/bczengel>, Ilya Mochalov <https://github.com/chrootsu>
Copyright (c) JS Foundation and other contributors <https://js.foundation/>

Lodash is based on Underscore.js, copyright Jeremy Ashkenas,
DocumentCloud and Investigative Reporters & Editors <http://underscorejs.org/>

This software consists of voluntary contributions made by many
individuals. For exact contribution history, see the revision history
available at the following locations:
- https://github.com/lodash/lodash
- https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/lodash
- https://github.com/elastic/kibana/tree/master/packages/elastic-safer-lodash-set

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Loading

0 comments on commit fc5bc6b

Please sign in to comment.