Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
7e748a6
chore: disallow `document` and `window` via eslint for React
spmonahan Aug 16, 2023
1c202d1
disable 'no-restricted-globals' for tests
spmonahan Aug 16, 2023
e82e43c
chore: update no-restricted-globals eslint rules
spmonahan Sep 6, 2023
3b634d4
temporarily disable stricter rules for @fluentui/react-components
spmonahan Oct 4, 2023
fb11468
update @fluentui/react API snapshot
spmonahan Oct 4, 2023
8b7370c
fix lint errors
spmonahan Oct 9, 2023
30f6bdc
change files
spmonahan Oct 9, 2023
bcfdb6a
add lint exception
spmonahan Oct 9, 2023
7481959
change files
spmonahan Oct 9, 2023
7db8456
wire up globals where needed
spmonahan Oct 9, 2023
09f233f
change files
spmonahan Oct 9, 2023
9ab27f4
fix: address lint for restricted globals
spmonahan Oct 9, 2023
b218faa
change files
spmonahan Oct 9, 2023
4f270db
fix: lint errors and explicit exports
spmonahan Oct 9, 2023
6fc8275
change files
spmonahan Oct 9, 2023
157cb08
add lint exception
spmonahan Oct 10, 2023
2a9a16f
update eslint configs
spmonahan Oct 10, 2023
a32e1d4
lint for no-restricted-globals
spmonahan Oct 10, 2023
8919bb1
lint no-restricted-globals
spmonahan Oct 10, 2023
320e1fe
lint no-restricted-globals
spmonahan Oct 10, 2023
8e48bf7
lint no-restricted-globals
spmonahan Oct 10, 2023
679bbc9
lint no-restricted-globals
spmonahan Oct 10, 2023
36ddc96
lint no-restricted-globals
spmonahan Oct 10, 2023
ecdd3cd
lint no-restricted-globals
spmonahan Oct 10, 2023
c7dbb0d
lint no-restricted-globals
spmonahan Oct 10, 2023
fa8341f
lint no-restricted-globals
spmonahan Oct 10, 2023
922bcc4
wip
spmonahan Oct 10, 2023
adc618a
re-work based on tests
spmonahan Oct 11, 2023
9ad9155
change files
spmonahan Oct 11, 2023
22cdc22
cleanup from reviewing PR
spmonahan Oct 11, 2023
7ec3d32
add @fluentui/react-window-provider to deps
spmonahan Oct 11, 2023
b8046ef
update useOnClickOutside to use the correct context
spmonahan Oct 11, 2023
afa5923
remove unnecessary dep
spmonahan Oct 11, 2023
1f14814
expand type
spmonahan Oct 11, 2023
85b689f
update reference
spmonahan Oct 13, 2023
9750e06
fix: Calendar gets `window` references from `FluentProvider` context.
spmonahan Oct 13, 2023
538a08c
feat: DatePicker gets `window` references from `FluentProvider` context.
spmonahan Oct 13, 2023
bb5d214
sync dependency version
spmonahan Oct 13, 2023
438a3b7
fix window/document usage
spmonahan Oct 13, 2023
0fe943e
disable 'no-restricted-globals' lint rule for react-docsite-components
spmonahan Oct 13, 2023
959e8e2
disable 'no-restricted-globals' lint rule for apps
spmonahan Oct 13, 2023
bd4be81
disable 'no-restricted-globals' lint rule for react-examples
spmonahan Oct 13, 2023
8749bc8
updates to handle
spmonahan Oct 17, 2023
fe4085f
change files
spmonahan Oct 31, 2023
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
3 changes: 2 additions & 1 deletion apps/perf-test-react-components/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"root": true,
"rules": {
"@griffel/styles-file": "off",
"no-console": "off"
"no-console": "off",
"no-restricted-globals": "off"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import { teamsLightTheme } from '@fluentui/react-theme';
const LayoutShift: React.FunctionComponent = ({ children }) => {
// eslint-disable-next-line no-restricted-properties
React.useLayoutEffect(() => {
// eslint-disable-next-line no-restricted-globals
if (document.body) {
// Accessing the offsetWidth forces reflow (browser synchronously calculates style and layout.
// This allows us to measure theme impact on the rendering performance.
// eslint-disable-next-line no-restricted-globals
document.body.offsetWidth;
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { mergeClasses, makeStyles, createDOMRenderer } from '@griffel/core';
import * as React from 'react';

const renderer = createDOMRenderer(document);
const renderer =
// eslint-disable-next-line no-restricted-globals
createDOMRenderer(document);

const useStyles = makeStyles({
view: {
Expand Down
3 changes: 2 additions & 1 deletion apps/perf-test/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extends": ["plugin:@fluentui/eslint-plugin/react"],
"root": true,
"rules": {
"no-console": "off"
"no-console": "off",
"no-restricted-globals": "off"
}
}
1 change: 1 addition & 0 deletions apps/pr-deploy-site/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// turn off conflicting or unwanted rules from normal set
"curly": "off",
"no-var": "off",
"no-restricted-globals": "off",
"vars-on-top": "off",
"prefer-arrow-callback": "off"
}
Expand Down
3 changes: 2 additions & 1 deletion apps/public-docsite-resources/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/explicit-member-accessibility": "off",
"@typescript-eslint/member-ordering": "off",
"deprecation/deprecation": "off"
"deprecation/deprecation": "off",
"no-restricted-globals": "off"
}
}
3 changes: 2 additions & 1 deletion apps/public-docsite-v9/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/jsx-no-bind": "off",
"deprecation/deprecation": "off",
"import/no-extraneous-dependencies": ["error", { "packageDir": [".", "../.."] }]
"import/no-extraneous-dependencies": ["error", { "packageDir": [".", "../.."] }],
"no-restricted-globals": "off"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const useDebounce = (fn: (...args: unknown[]) => void, duration: number)
return React.useCallback(
(...args: unknown[]) => {
clearTimeout(timeoutRef.current);
// eslint-disable-next-line no-restricted-globals
timeoutRef.current = window.setTimeout(() => {
fn(...args);
}, duration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export const Toc = ({ stories }: { stories: TocItem[] }) => {
);

stories.forEach(link => {
// eslint-disable-next-line no-restricted-globals
const element = document.getElementById(nameToHash(link.name));
if (element) {
observer.observe(element);
Expand Down
1 change: 1 addition & 0 deletions apps/public-docsite/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"@typescript-eslint/no-explicit-any": "off",
"deprecation/deprecation": "off",
"import/no-webpack-loader-syntax": "off", // ok in this project
"no-restricted-globals": "off",
"prefer-const": "off",
"react/jsx-no-bind": "off"
}
Expand Down
4 changes: 3 additions & 1 deletion apps/react-18-tests-v8/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"extends": ["plugin:@fluentui/eslint-plugin/react"],
"root": true,
"rules": {}
"rules": {
"no-restricted-globals": "off"
}
}
5 changes: 4 additions & 1 deletion apps/react-18-tests-v8/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import * as React from 'react';
import { createRoot } from 'react-dom/client';
import { App } from './App';

const root = createRoot(document.getElementById('root') as HTMLElement);
const root = createRoot(
// eslint-disable-next-line no-restricted-globals
document.getElementById('root') as HTMLElement,
);
root.render(
<React.StrictMode>
<App />
Expand Down
4 changes: 3 additions & 1 deletion apps/react-18-tests-v9/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"extends": ["plugin:@fluentui/eslint-plugin/react"],
"root": true,
"rules": {}
"rules": {
"no-restricted-globals": "off"
}
}
5 changes: 4 additions & 1 deletion apps/react-18-tests-v9/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import * as React from 'react';
import { createRoot } from 'react-dom/client';
import { App } from './App';

const root = createRoot(document.getElementById('root') as HTMLElement);
const root = createRoot(
// eslint-disable-next-line no-restricted-globals
document.getElementById('root') as HTMLElement,
);
root.render(
<React.StrictMode>
<App />
Expand Down
3 changes: 2 additions & 1 deletion apps/recipes-react-components/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/jsx-no-bind": "off",
"deprecation/deprecation": "off",
"import/no-extraneous-dependencies": ["error", { "packageDir": [".", "../.."] }]
"import/no-extraneous-dependencies": ["error", { "packageDir": [".", "../.."] }],
"no-restricted-globals": "off"
}
}
3 changes: 2 additions & 1 deletion apps/ssr-tests-v9/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extends": ["plugin:@fluentui/eslint-plugin/node"],
"root": true,
"rules": {
"import/no-extraneous-dependencies": ["error", { "packageDir": ["../../", "./"] }]
"import/no-extraneous-dependencies": ["error", { "packageDir": ["../../", "./"] }],
"no-restricted-globals": "off"
}
}
3 changes: 2 additions & 1 deletion apps/stress-test/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extends": ["plugin:@fluentui/eslint-plugin/node"],
"root": true,
"rules": {
"import/no-extraneous-dependencies": ["error", { "packageDir": ["../../", "./"] }]
"import/no-extraneous-dependencies": ["error", { "packageDir": ["../../", "./"] }],
"no-restricted-globals": "off"
}
}
1 change: 1 addition & 0 deletions apps/theming-designer/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"rules": {
"@typescript-eslint/no-explicit-any": "off",
"deprecation/deprecation": "off",
"no-restricted-globals": "off",
"prefer-const": "off"
}
}
3 changes: 2 additions & 1 deletion apps/vr-tests-react-components/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"@typescript-eslint/naming-convention": "off",
"@typescript-eslint/jsx-no-bind": "off",
"deprecation/deprecation": "off",
"import/no-extraneous-dependencies": ["error", { "packageDir": [".", "../.."] }]
"import/no-extraneous-dependencies": ["error", { "packageDir": [".", "../.."] }],
"no-restricted-globals": "off"
}
}
3 changes: 2 additions & 1 deletion apps/vr-tests/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/jsx-no-bind": "off",
"deprecation/deprecation": "off",
"import/no-extraneous-dependencies": ["error", { "packageDir": [".", "../.."] }]
"import/no-extraneous-dependencies": ["error", { "packageDir": [".", "../.."] }],
"no-restricted-globals": "off"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "chore: disable lint for no-restricted-globals",
"packageName": "@fluentui/cra-template",
"email": "seanmonahan@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "feat: allow `document` and `window` globals to be passed in where needed.",
"packageName": "@fluentui/dom-utilities",
"email": "seanmonahan@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "chore: disable global `document` and `window` access for React.",
"packageName": "@fluentui/eslint-plugin",
"email": "seanmonahan@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "chore: disable lint for no-restricted-globals",
"packageName": "@fluentui/global-context",
"email": "seanmonahan@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix: address lint for restricted globals",
"packageName": "@fluentui/merge-styles",
"email": "seanmonahan@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix: lint errors",
"packageName": "@fluentui/public-docsite-setup",
"email": "seanmonahan@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "feat: use `document` and `window` globals from context",
"packageName": "@fluentui/react",
"email": "seanmonahan@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix: use globals from context",
"packageName": "@fluentui/react-calendar-compat",
"email": "seanmonahan@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "chore: disable lint for no-restricted-globals",
"packageName": "@fluentui/react-datepicker-compat",
"email": "seanmonahan@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "feat: update `getFileTypeIconsSuffix()` to take optional parameter for `window` reference.",
"packageName": "@fluentui/react-file-type-icons",
"email": "seanmonahan@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "feat: allow `document` and `window` globals to be passed in where needed.",
"packageName": "@fluentui/react-focus",
"email": "seanmonahan@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "chore: disable lint for no-retricted-globals",
"packageName": "@fluentui/react-motion-preview",
"email": "seanmonahan@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "chore: disable lint for no-restricted-globals",
"packageName": "@fluentui/react-shared-contexts",
"email": "seanmonahan@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "chore: update to get `window` reference via `getWindow()`.",
"packageName": "@fluentui/react-utilities",
"email": "seanmonahan@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix: lint errors and explicit exports",
"packageName": "@fluentui/react-window-provider",
"email": "seanmonahan@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "chore: lint exception comment",
"packageName": "@fluentui/set-version",
"email": "seanmonahan@microsoft.com",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "feat: allow `document` and `window` globals to be passed in where needed.",
"packageName": "@fluentui/utilities",
"email": "seanmonahan@microsoft.com",
"dependentChangeType": "patch"
}
6 changes: 5 additions & 1 deletion packages/cra-template/template/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ mergeStyles({
},
});

ReactDOM.render(<App />, document.getElementById('root'));
ReactDOM.render(
<App />,
// eslint-disable-next-line no-restricted-globals
document.getElementById('root'),
);

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
Expand Down
7 changes: 3 additions & 4 deletions packages/dom-utilities/etc/dom-utilities.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ export const DATA_PORTAL_ATTRIBUTE = "data-portal-element";
export function elementContains(parent: HTMLElement | null, child: HTMLElement | null, allowVirtualParents?: boolean): boolean;

// @public
export function elementContainsAttribute(element: HTMLElement, attribute: string): string | null;
export function elementContainsAttribute(element: HTMLElement, attribute: string, doc?: Document): string | null;

// @public
export function findElementRecursive(element: HTMLElement | null, matchFunction: (element: HTMLElement) => boolean): HTMLElement | null;
export function findElementRecursive(element: HTMLElement | null, matchFunction: (element: HTMLElement) => boolean, doc?: Document): HTMLElement | null;

// @public
export function getChildren(parent: HTMLElement, allowVirtualChildren?: boolean): HTMLElement[];
Expand All @@ -38,15 +38,14 @@ export interface IVirtualElement extends HTMLElement {
}

// @public
export function portalContainsElement(target: HTMLElement, parent?: HTMLElement): boolean;
export function portalContainsElement(target: HTMLElement, parent?: HTMLElement, doc?: Document): boolean;

// @public
export function setPortalAttribute(element: HTMLElement): void;

// @public
export function setVirtualParent(child: HTMLElement, parent: HTMLElement | null): void;


// (No @packageDocumentation comment for this package)

```
8 changes: 6 additions & 2 deletions packages/dom-utilities/src/elementContainsAttribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ import { findElementRecursive } from './findElementRecursive';
* @param attribute - the attribute to search for
* @returns the value of the first instance found
*/
export function elementContainsAttribute(element: HTMLElement, attribute: string): string | null {
const elementMatch = findElementRecursive(element, (testElement: HTMLElement) => testElement.hasAttribute(attribute));
export function elementContainsAttribute(element: HTMLElement, attribute: string, doc?: Document): string | null {
const elementMatch = findElementRecursive(
element,
(testElement: HTMLElement) => testElement.hasAttribute(attribute),
doc,
);

return elementMatch && elementMatch.getAttribute(attribute);
}
5 changes: 4 additions & 1 deletion packages/dom-utilities/src/findElementRecursive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ import { getParent } from './getParent';
export function findElementRecursive(
element: HTMLElement | null,
matchFunction: (element: HTMLElement) => boolean,
doc?: Document,
): HTMLElement | null {
if (!element || element === document.body) {
// eslint-disable-next-line no-restricted-globals
doc ??= document;
if (!element || element === doc.body) {
return null;
}
return matchFunction(element) ? element : findElementRecursive(getParent(element), matchFunction);
Expand Down
Loading