Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.17] Fix eslint rule for restricting certain lodash imports (#151023) #151550

Merged
merged 2 commits into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 78 additions & 81 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,50 +170,49 @@ const DEV_PATTERNS = [
const RESTRICTED_IMPORTS = [
{
name: 'lodash',
importNames: ['set', 'setWith'],
message: 'Please use @elastic/safer-lodash-set instead',
importNames: ['set', 'setWith', 'template'],
message:
'lodash.set/setWith: Please use @elastic/safer-lodash-set instead.\n' +
'lodash.template: Function is unsafe, and not compatible with our content security policy.',
},
{
name: 'lodash.set',
message: 'Please use @elastic/safer-lodash-set instead',
message: 'Please use @elastic/safer-lodash-set/set instead',
},
{
name: 'lodash.setwith',
message: 'Please use @elastic/safer-lodash-set instead',
message: 'Please use @elastic/safer-lodash-set/setWith instead',
},
{
name: 'lodash/set',
message: 'Please use @elastic/safer-lodash-set instead',
message: 'Please use @elastic/safer-lodash-set/set instead',
},
{
name: 'lodash/setWith',
message: 'Please use @elastic/safer-lodash-set instead',
message: 'Please use @elastic/safer-lodash-set/setWith instead',
},
{
name: 'lodash/fp',
importNames: ['set', 'setWith', 'assoc', 'assocPath'],
message: 'Please use @elastic/safer-lodash-set instead',
importNames: ['set', 'setWith', 'assoc', 'assocPath', 'template'],
message:
'lodash.set/setWith/assoc/assocPath: Please use @elastic/safer-lodash-set/fp instead\n' +
'lodash.template: Function is unsafe, and not compatible with our content security policy.',
},
{
name: 'lodash/fp/set',
message: 'Please use @elastic/safer-lodash-set instead',
message: 'Please use @elastic/safer-lodash-set/fp/set instead',
},
{
name: 'lodash/fp/setWith',
message: 'Please use @elastic/safer-lodash-set instead',
message: 'Please use @elastic/safer-lodash-set/fp/setWith instead',
},
{
name: 'lodash/fp/assoc',
message: 'Please use @elastic/safer-lodash-set instead',
message: 'Please use @elastic/safer-lodash-set/fp/assoc instead',
},
{
name: 'lodash/fp/assocPath',
message: 'Please use @elastic/safer-lodash-set instead',
},
{
name: 'lodash',
importNames: ['template'],
message: 'lodash.template is unsafe, and not compatible with our content security policy.',
message: 'Please use @elastic/safer-lodash-set/fp/assocPath instead',
},
{
name: 'lodash.template',
Expand All @@ -223,11 +222,6 @@ const RESTRICTED_IMPORTS = [
name: 'lodash/template',
message: 'lodash.template is unsafe, and not compatible with our content security policy.',
},
{
name: 'lodash/fp',
importNames: ['template'],
message: 'lodash.template is unsafe, and not compatible with our content security policy.',
},
{
name: 'lodash/fp/template',
message: 'lodash.template is unsafe, and not compatible with our content security policy.',
Expand Down Expand Up @@ -787,47 +781,54 @@ module.exports = {
{
files: ['**/*.{js,mjs,ts,tsx}'],
rules: {
'no-restricted-imports': [
2,
'no-restricted-imports': ['error', ...RESTRICTED_IMPORTS],
'no-restricted-modules': [
'error',
{
paths: RESTRICTED_IMPORTS,
name: 'lodash.set',
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.template',
message:
'lodash.template is unsafe, and not compatible with our content security policy.',
},
{
name: 'lodash/set',
message: 'Please use @elastic/safer-lodash-set instead',
},
{
name: 'lodash/setWith',
message: 'Please use @elastic/safer-lodash-set instead',
},
{
name: 'lodash/template',
message:
'lodash.template is unsafe, and not compatible with our content security policy.',
},
],
name: 'lodash.setwith',
message: 'Please use @elastic/safer-lodash-set instead',
},
{
name: 'lodash.template',
message:
'lodash.template is unsafe, and not compatible with our content security policy.',
},
{
name: 'lodash/set',
message: 'Please use @elastic/safer-lodash-set/set instead',
},
{
name: 'lodash/setWith',
message: 'Please use @elastic/safer-lodash-set/setWith instead',
},
{
name: 'lodash/fp/set',
message: 'Please use @elastic/safer-lodash-set/fp/set instead',
},
{
name: 'lodash/fp/setWith',
message: 'Please use @elastic/safer-lodash-set/fp/setWith instead',
},
{
name: 'lodash/fp/assoc',
message: 'Please use @elastic/safer-lodash-set/fp/assoc instead',
},
{
name: 'lodash/fp/assocPath',
message: 'Please use @elastic/safer-lodash-set/fp/assocPath instead',
},
{
name: 'lodash/template',
message:
'lodash.template is unsafe, and not compatible with our content security policy.',
},
],
'no-restricted-properties': [
2,
'error',
{
object: 'lodash',
property: 'set',
Expand All @@ -838,18 +839,6 @@ module.exports = {
property: 'set',
message: 'Please use @elastic/safer-lodash-set instead',
},
{
object: 'lodash',
property: 'template',
message:
'lodash.template is unsafe, and not compatible with our content security policy.',
},
{
object: '_',
property: 'template',
message:
'lodash.template is unsafe, and not compatible with our content security policy.',
},
{
object: 'lodash',
property: 'setWith',
Expand Down Expand Up @@ -880,26 +869,34 @@ module.exports = {
property: 'assocPath',
message: 'Please use @elastic/safer-lodash-set instead',
},
{
object: 'lodash',
property: 'template',
message:
'lodash.template is unsafe, and not compatible with our content security policy.',
},
{
object: '_',
property: 'template',
message:
'lodash.template is unsafe, and not compatible with our content security policy.',
},
],
},
},
{
files: ['**/common/**/*.{js,mjs,ts,tsx}', '**/public/**/*.{js,mjs,ts,tsx}'],
rules: {
'no-restricted-imports': [
2,
'error',
...RESTRICTED_IMPORTS,
{
paths: [
...RESTRICTED_IMPORTS,
{
name: 'semver',
message: 'Please use "semver/*/{function}" instead',
},
{
name: '@kbn/rule-data-utils',
message: `Import directly from @kbn/rule-data-utils/* submodules in public/common code`,
},
],
name: 'semver',
message: 'Please use "semver/*/{function}" instead',
},
{
name: '@kbn/rule-data-utils',
message: `Import directly from @kbn/rule-data-utils/* submodules in public/common code`,
},
],
},
Expand Down
2 changes: 2 additions & 0 deletions packages/elastic-apm-synthtrace/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ NPM_MODULE_EXTRA_FILES = [

RUNTIME_DEPS = [
"//packages/elastic-datemath",
"//packages/elastic-safer-lodash-set",
"@npm//@elastic/elasticsearch",
"@npm//lodash",
"@npm//moment",
Expand All @@ -38,6 +39,7 @@ RUNTIME_DEPS = [

TYPES_DEPS = [
"//packages/elastic-datemath:npm_module_types",
"//packages/elastic-safer-lodash-set",
"@npm//@elastic/elasticsearch",
"@npm//moment",
"@npm//p-limit",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import { set } from 'lodash';
import { set } from '@elastic/safer-lodash-set';
import { getObserverDefaults } from '../..';
import { Fields } from '../entity';

Expand Down
2 changes: 1 addition & 1 deletion packages/elastic-safer-lodash-set/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Lodash v4.x.
## Example Usage

```js
const { set } = require('@elastic/safer-loadsh-set');
const { set } = require('@elastic/safer-lodash-set');

const object = { a: [{ b: { c: 3 } }] };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import { set } from 'lodash';
import { set } from '@elastic/safer-lodash-set';
import {
buildInlineScriptForPhraseFilter,
buildPhraseFilter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import { setMockValues } from '../../../../__mocks__/kea_logic';
import React from 'react';

import { shallow } from 'enzyme';
import { set } from 'lodash/fp';

import { set } from '@elastic/safer-lodash-set/fp';

import { SuggestionsCallout } from '../components/suggestions_callout';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ import React from 'react';

import { shallow } from 'enzyme';

import { set } from 'lodash/fp';

import { EuiTab } from '@elastic/eui';
import { set } from '@elastic/safer-lodash-set/fp';

import { getPageHeaderTabs, getPageTitle } from '../../../../test_helpers';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import '../../../__mocks__/engine_logic.mock';
import React from 'react';

import { shallow } from 'enzyme';
import { set } from 'lodash/fp';

import { set } from '@elastic/safer-lodash-set/fp';

import { CurationsTable, EmptyState } from '../components';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import { setMockValues } from '../../../../__mocks__/kea_logic';
import React from 'react';

import { shallow } from 'enzyme';
import { set } from 'lodash/fp';

import { set } from '@elastic/safer-lodash-set/fp';

import { SuggestionsCallout } from '../../curations/components/suggestions_callout';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
*/

import moment from 'moment';
import { set, unset } from 'lodash';
import { set } from '@elastic/safer-lodash-set';
import { unset } from 'lodash';
import { STANDALONE_CLUSTER_CLUSTER_UUID } from '../../../common/constants';
import { handleResponse, getNodeInfo } from './get_node_info';
import { LegacyRequest } from '../../types';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* 2.0.
*/

import { pickBy, get, isEmpty, isString, unset, set, intersection } from 'lodash';
import { set } from '@elastic/safer-lodash-set';
import { pickBy, get, isEmpty, isString, unset, intersection } from 'lodash';
import satisfies from 'semver/functions/satisfies';
import {
EuiFlexGroup,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
*/

import moment from 'moment-timezone';
import { has, mapKeys, set, unset, find } from 'lodash';
import { set } from '@elastic/safer-lodash-set';
import { has, mapKeys, unset, find } from 'lodash';
import { schema } from '@kbn/config-schema';
import { produce } from 'immer';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
*/

import moment from 'moment-timezone';
import { set, unset, has, difference, filter, find, map, mapKeys, uniq } from 'lodash';
import { set } from '@elastic/safer-lodash-set';
import { unset, has, difference, filter, find, map, mapKeys, uniq } from 'lodash';
import { schema } from '@kbn/config-schema';
import { produce } from 'immer';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

import { produce } from 'immer';
import { satisfies } from 'semver';
import { filter, reduce, mapKeys, each, set, unset, uniq, map, has } from 'lodash';
import { set } from '@elastic/safer-lodash-set';
import { filter, reduce, mapKeys, each, unset, uniq, map, has } from 'lodash';
import { packSavedObjectType } from '../../../common/types';
import {
PACKAGE_POLICY_SAVED_OBJECT_TYPE,
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/reporting/server/lib/content_stream.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { set } from 'lodash';
import { set } from '@elastic/safer-lodash-set';
import { elasticsearchServiceMock } from 'src/core/server/mocks';
import { createMockLevelLogger } from '../test_helpers';
import { ContentStream } from './content_stream';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { set } from 'lodash';
import { set } from '@elastic/safer-lodash-set';
import { durationToNumber } from '../../../common/schema_utils';
import { HeadlessChromiumDriver } from '../../browsers';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { UnwrapPromise } from '@kbn/utility-types';
import { set } from 'lodash';
import { set } from '@elastic/safer-lodash-set';
import { ElasticsearchClient } from 'src/core/server';
import { statuses } from '../../lib';
import { createMockConfigSchema, createMockReportingCore } from '../../test_helpers';
Expand Down
Loading