From a8b0fb19347e7823a03fbd9aa5c60c9c5d434535 Mon Sep 17 00:00:00 2001 From: Ryan Cebulko Date: Fri, 26 Feb 2021 11:59:38 -0500 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Fixit:=20create=20src/core?= =?UTF-8?q?=20with=20eslint=20rule=20disallowing=20imports=20(#32916)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Create src/core directory with lint config * Update references to original assert location * Add comment to eslint config * Add Justin as owner * Lint fixes * Justion `required: true` --- extensions/amp-accordion/1.0/base-element.js | 2 +- extensions/amp-selector/1.0/base-element.js | 2 +- src/core/.eslintrc.js | 27 ++++++++++++++++++++ src/core/OWNERS | 14 ++++++++++ src/{ => core}/assert.js | 0 src/log.js | 2 +- src/utils/date.js | 2 +- test/unit/test-assert.js | 2 +- 8 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 src/core/.eslintrc.js create mode 100644 src/core/OWNERS rename src/{ => core}/assert.js (100%) diff --git a/extensions/amp-accordion/1.0/base-element.js b/extensions/amp-accordion/1.0/base-element.js index fc1231c78c3d..278386181065 100644 --- a/extensions/amp-accordion/1.0/base-element.js +++ b/extensions/amp-accordion/1.0/base-element.js @@ -23,7 +23,7 @@ import { } from './component'; import {PreactBaseElement} from '../../../src/preact/base-element'; import {childElementsByTag, toggleAttribute} from '../../../src/dom'; -import {pureDevAssert as devAssert} from '../../../src/assert'; +import {pureDevAssert as devAssert} from '../../../src/core/assert'; import {dict, memo} from '../../../src/utils/object'; import {forwardRef} from '../../../src/preact/compat'; import {toArray} from '../../../src/types'; diff --git a/extensions/amp-selector/1.0/base-element.js b/extensions/amp-selector/1.0/base-element.js index fe91b3b4f9a6..01dfba651546 100644 --- a/extensions/amp-selector/1.0/base-element.js +++ b/extensions/amp-selector/1.0/base-element.js @@ -23,7 +23,7 @@ import { toggleAttribute, tryFocus, } from '../../../src/dom'; -import {pureDevAssert as devAssert} from '../../../src/assert'; +import {pureDevAssert as devAssert} from '../../../src/core/assert'; import {dict} from '../../../src/utils/object'; import {toArray} from '../../../src/types'; import {useCallback, useLayoutEffect, useRef} from '../../../src/preact'; diff --git a/src/core/.eslintrc.js b/src/core/.eslintrc.js new file mode 100644 index 000000000000..950c7f2c8769 --- /dev/null +++ b/src/core/.eslintrc.js @@ -0,0 +1,27 @@ +/** + * Copyright 2021 The AMP HTML Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS-IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +module.exports = { + 'rules': { + 'no-restricted-imports': [ + 'error', + { + // Disallow importing dependencies from outside this directory + 'patterns': ['..'], + }, + ], + }, +}; diff --git a/src/core/OWNERS b/src/core/OWNERS new file mode 100644 index 000000000000..868639487650 --- /dev/null +++ b/src/core/OWNERS @@ -0,0 +1,14 @@ +// For an explanation of the OWNERS rules and syntax, see: +// https://github.com/ampproject/amp-github-apps/blob/master/owners/OWNERS.example + +{ + rules: [ + { + owners: [ + {name: 'dvoytenko'}, + {name: 'jridgewell', required: true}, + {name: 'ampproject/wg-performance'}, + ], + }, + ], +} diff --git a/src/assert.js b/src/core/assert.js similarity index 100% rename from src/assert.js rename to src/core/assert.js diff --git a/src/log.js b/src/log.js index 4ba8716eafb5..5f41f77936e6 100644 --- a/src/log.js +++ b/src/log.js @@ -14,7 +14,7 @@ * limitations under the License. */ -import {USER_ERROR_SENTINEL} from './assert'; +import {USER_ERROR_SENTINEL} from './core/assert'; import {getMode} from './mode'; import {internalRuntimeVersion} from './internal-version'; import {isArray, isEnumValue} from './types'; diff --git a/src/utils/date.js b/src/utils/date.js index 0b864d23cae8..d549610ec53e 100644 --- a/src/utils/date.js +++ b/src/utils/date.js @@ -17,7 +17,7 @@ import { pureDevAssert as devAssert, pureUserAssert as userAssert, -} from '../assert'; +} from '../core/assert'; /** * Parses the date using the `Date.parse()` rules. Additionally supports the diff --git a/test/unit/test-assert.js b/test/unit/test-assert.js index 264e98189795..58355f840f65 100644 --- a/test/unit/test-assert.js +++ b/test/unit/test-assert.js @@ -18,7 +18,7 @@ import { USER_ERROR_SENTINEL, pureDevAssert as devAssert, pureUserAssert as userAssert, -} from '../../src/assert'; +} from '../../src/core/assert'; describes.sandboxed('assertions', {}, () => { describe('devAssert', () => {