Skip to content

Commit

Permalink
Merge pull request #176 from airbnb/ts-ignore
Browse files Browse the repository at this point in the history
Replace all `@ts-ignore` with `@ts-expect-error`
  • Loading branch information
malash authored Nov 21, 2022
2 parents 1b10f19 + 312740c commit 65a0c74
Show file tree
Hide file tree
Showing 28 changed files with 66 additions and 70 deletions.
9 changes: 9 additions & 0 deletions packages/beemo-dev/configs/eslint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,15 @@ const config: ESLintConfig = {
// https://github.com/typescript-eslint/typescript-eslint/issues/2477
'no-undef': 'off',
'no-tabs': 'error',
'@typescript-eslint/ban-ts-comment': [
'error',
{
'ts-expect-error': false,
'ts-ignore': true,
'ts-nocheck': false,
'ts-check': false,
},
],
},
};

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/config/webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ export const getWebpackConfig = ({
},
],
},
// @ts-ignore
// @ts-expect-error
plugins: [
new MiniCssExtractPlugin({
filename: `[name].${CSS_FILE_EXT[target] ?? 'wxss'}`,
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/__tests__/container.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ describe('AdaptorInstance', () => {
act(() => {
render(<App />);
});
// @ts-ignore
// @ts-expect-error
expect(renderedCount).toBe(0);
// @ts-ignore
// @ts-expect-error
expect(effectCount).toBe(0);
act(() => {
renderedSetCount(10);
renderedSetCount(20);
});
// @ts-ignore
// @ts-expect-error
expect(renderedCount).toBe(20);
// @ts-ignore
// @ts-expect-error
expect(effectCount).toBe(20);
});
});
1 change: 0 additions & 1 deletion packages/core/src/__tests__/helpers/adaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { applyDiff } from '../../utils/diff';
export class TestingAdaptorInstance extends AdaptorInstance {
public data: any = {};

// @ts-ignore
// eslint-disable-next-line
public setData = (val: any) => {};

Expand Down
7 changes: 3 additions & 4 deletions packages/core/src/__tests__/updates.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ describe('updates', () => {
let adaptor: Adaptor;

beforeAll(() => {
// @ts-ignore
global.Page = function Page(options: WeChatPageConfig) {
const instance: WeChatInstance = {
setData(data) {
Expand All @@ -22,7 +21,7 @@ describe('updates', () => {
});

afterAll(() => {
// @ts-ignore
// @ts-expect-error
delete global.Page;
});

Expand Down Expand Up @@ -79,7 +78,7 @@ describe('updates', () => {
adaptor.run(<TestComp />);
diff = null;

// @ts-ignore
// @ts-expect-error
updater(e => e);
expect(diff).toEqual(null);
});
Expand All @@ -101,7 +100,7 @@ describe('updates', () => {
adaptor.run(<TestComp />);
diff = null;

// @ts-ignore
// @ts-expect-error
updater(false);
expect(Object.keys(diff)).toEqual(['c[0].sid']);
});
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/adaptor/__tests__/wechat.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { WeChatAdaptor, WeChatPageConfig, WeChatInstance } from '../wechat';
describe('WeChatAdaptor', () => {
let data: any;
beforeAll(() => {
// @ts-ignore
global.Page = function Page(options: WeChatPageConfig) {
const instance: WeChatInstance = {
setData(newData) {
Expand All @@ -23,7 +22,7 @@ describe('WeChatAdaptor', () => {
});

afterAll(() => {
// @ts-ignore
// @ts-expect-error
delete global.Page;
});
});
3 changes: 1 addition & 2 deletions packages/core/src/adaptor/wechat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,13 @@ export class WeChatAdaptor extends Adaptor {
const { type } = this;
if (type === 'page') {
const pageConfig: WeChatPageConfig = pageLifecycles;
// @ts-ignore FIXME:
// @ts-expect-error FIXME:
Page({
...pageConfig,
...eventHandler,
});
} else if (type === 'component') {
const componentConfig: WeChatComponentConfig = {
// @ts-ignore FIXME:
methods: { ...pageLifecycles, ...eventHandler },
};
Component(componentConfig);
Expand Down
8 changes: 3 additions & 5 deletions packages/core/src/components/factoryComponents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ const factoryComponent = <
) => {
const displayName = pascalCase(component);
// FIXME: Not all components have `children`. We should fix the type later.
const comp = (props: P, ref: React.Ref<PublicInstance>) =>
// @ts-ignore
createElement(component, { ...props, ref })
;

const comp = (props: P, ref: React.Ref<PublicInstance>) =>
// @ts-expect-error
createElement(component, { ...props, ref });
const compWithRef = forwardRef<PublicInstance, P>(comp);
compWithRef.displayName = displayName;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe('universal lifecycles', () => {
// re-render the component with no UI changed
wrapper.setManuallyResolvedUpdateCallback(false);
renderedEffectCallback.mockClear();
// @ts-ignore
// @ts-expect-error
forceUpdate();
expect(renderedEffectCallback).toBeCalled();
});
Expand All @@ -92,9 +92,9 @@ describe('universal lifecycles', () => {
const wrapper = render(<Page />);
wrapper.setManuallyResolvedUpdateCallback(true);
// re-render the component
// @ts-ignore
// @ts-expect-error
update();
// @ts-ignore
// @ts-expect-error
update();

renderedEffectCallback.mockClear();
Expand Down Expand Up @@ -207,7 +207,6 @@ describe('universal lifecycles', () => {
let mockSetData = jest.fn();
let update: () => void = () => {};
let wrapper: RenderResult;
// @ts-ignore
const originalPage = global.Page;

beforeEach(() => {
Expand All @@ -233,7 +232,6 @@ describe('universal lifecycles', () => {
});

afterEach(() => {
// @ts-ignore
global.Page = originalPage;
setGojiBlockingMode(false);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/patchGlobalObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ class ObjectE {
}
}

// @ts-ignore
// @ts-expect-error
Object.e = new ObjectE();
8 changes: 4 additions & 4 deletions packages/core/src/reconciler/__tests__/instance.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('ElementInstance', () => {

describe('getSubtreeId', () => {
beforeAll(() => {
// @ts-ignore
// @ts-expect-error
process.env.GOJI_WRAPPED_COMPONENTS = [];
});
const view = () =>
Expand Down Expand Up @@ -172,13 +172,13 @@ describe('ElementInstance', () => {
expect(renderCount).toBe(1);

// non batched
// @ts-ignore
// @ts-expect-error
callback();
act(() => {});
expect(renderCount).toBe(3);

// batched
// @ts-ignore
// @ts-expect-error
batchedUpdates(callback);
act(() => {});
expect(renderCount).toBe(4);
Expand Down Expand Up @@ -255,7 +255,7 @@ describe('ElementInstance', () => {
return textNodes.map(text => (text as TextNode).text);
};
expect(getTextList()).toEqual(['1', '2', '3']);
// @ts-ignore
// @ts-expect-error
setItemsCallback([2, 1, 3]);
expect(getTextList()).toEqual(['2', '1', '3']);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/testUtils/act.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export function act(callback: () => Thenable<unknown> | void) {
() => {
if (
actingUpdatesScopeDepth > 1 ||
// @ts-ignore
// @ts-expect-error
(isSchedulerMocked === true && previousIsSomeRendererActing === true)
) {
onDone();
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/testUtils/forks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ export const warningWithoutStack = (
// only support Node yet
export const enqueueTask = setImmediate;

// @ts-ignore
// @ts-expect-error
export const ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED; // eslint-disable-line no-underscore-dangle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ describe('styleAttrStringify', () => {
test('invalid values', () => {
expect(styleAttrStringify(undefined)).toBe('');
expect(styleAttrStringify({})).toBe('');
// @ts-ignore
// @ts-expect-error
expect(styleAttrStringify({ width: null, height: undefined, top: 0 })).toBe('top:0;');
});

Expand Down
2 changes: 1 addition & 1 deletion packages/testing-library/src/utils/toJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function realToJSON(inst, { omitProps = [] }: { omitProps?: Array<string> }) {
}

export function toJSON(node: ReactTestInstance, options = {}) {
// @ts-ignore
// @ts-expect-error
// eslint-disable-next-line no-underscore-dangle
const stateNode = node?._fiber?.stateNode;
if (!stateNode) return null;
Expand Down
7 changes: 2 additions & 5 deletions packages/webpack-plugin/src/forked/providePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class PatchedProvidePlugin {
* @param {Record<string, string | string[]>} definitions the provided identifiers
*/
constructor(definitions) {
// @ts-ignore
// @ts-expect-error
this.definitions = definitions;
}

Expand All @@ -35,7 +35,7 @@ class PatchedProvidePlugin {
* @returns {void}
*/
apply(compiler) {
// @ts-ignore
// @ts-expect-error
const definitions = this.definitions;
compiler.hooks.compilation.tap('ProvidePlugin', (compilation, { normalModuleFactory }) => {
compilation.dependencyTemplates.set(ConstDependency, new ConstDependency.Template());
Expand All @@ -46,7 +46,6 @@ class PatchedProvidePlugin {
/* patch start */
// Support `exclude` option
let provideFile = definitions[name];
// @ts-ignore
let excludeFiles = [];
if (
!Array.isArray(provideFile) &&
Expand Down Expand Up @@ -76,9 +75,7 @@ class PatchedProvidePlugin {
/* patch start */
// exclude files
const currentFile = parser.state.current.request;
// @ts-ignore
for (let i in excludeFiles) {
// @ts-ignore
if (currentFile.match(excludeFiles[i])) {
return false;
}
Expand Down
8 changes: 4 additions & 4 deletions packages/webpack-plugin/src/forked/splitChunksPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ export const normalizeCacheGroups = (cacheGroups, defaultSizeTypes) => {
}
if (typeof option === 'string' || option instanceof RegExp) {
const source = createCacheGroupSource({}, key, defaultSizeTypes);
// @ts-ignore
// @ts-expect-error
handlers.push((module, context, results) => {
if (checkTest(option, module, context)) {
results.push(source);
}
});
} else if (typeof option === 'function') {
const cache = new WeakMap();
// @ts-ignore
// @ts-expect-error
handlers.push((module, context, results) => {
const result = option(module);
if (result) {
Expand All @@ -118,7 +118,7 @@ export const normalizeCacheGroups = (cacheGroups, defaultSizeTypes) => {
});
} else {
const source = createCacheGroupSource(option, key, defaultSizeTypes);
// @ts-ignore
// @ts-expect-error
handlers.push((module, context, results) => {
if (
checkTest(option.test, module, context) &&
Expand All @@ -139,7 +139,7 @@ export const normalizeCacheGroups = (cacheGroups, defaultSizeTypes) => {
/** @type {CacheGroupSource[]} */
let results = [];
for (const fn of handlers) {
// @ts-ignore
// @ts-expect-error
fn(module, context, results);
}
return results;
Expand Down
10 changes: 5 additions & 5 deletions packages/webpack-plugin/src/plugins/collectUsedComponents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ export class GojiCollectUsedComponentsWebpackPlugin extends GojiBasedWebpackPlug
if (module.type.startsWith('javascript/')) {
for (const dependency of module.dependencies) {
// only process `@goji/core`
// @ts-ignore
// @ts-expect-error
if (dependency.request !== GOJI_CORE_PACKAGE_NAME) {
continue;
}
switch (dependency.type) {
case COMMON_JS_REQUIRE_DEPENDENCY_TYPE: {
compilation.warnings.push(
new WebpackError(
// @ts-ignore
// @ts-expect-error
`[GojiCollectUsedComponentsWebpackPlugin] \nGojiJS strongly recommend to use ES module in ${module.resource} otherwise the bridge file size optimization was disabled`,
),
);
Expand All @@ -57,17 +57,17 @@ export class GojiCollectUsedComponentsWebpackPlugin extends GojiBasedWebpackPlug
case HARMONY_IMPORT_SPECIFIER_DEPENDENCY_TYPE: {
// `dependency.ids` would be `[]` if this is a namespace import, which means `import * as xx from 'yy'`
// see https://github.com/webpack/webpack/blob/a3bef27457d8936f81525beaa633eb1931382dc0/lib/javascript/JavascriptParser.js#L1750
// @ts-ignore
// @ts-expect-error
if (!dependency.ids.length) {
compilation.warnings.push(
new WebpackError(
// @ts-ignore
// @ts-expect-error
`[GojiCollectUsedComponentsWebpackPlugin] \nShould not use \`import * as ${dependency.name} from '@goji/core'\` in ${module.resource}`,
),
);
return undefined;
}
// @ts-ignore
// @ts-expect-error
for (const id of dependency.ids) {
dependencyNamesSet.add(id);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/webpack-plugin/src/plugins/nohoist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class GojiNohoistWebpackPlugin extends GojiBasedWebpackPlugin {
(compilation: webpack.Compilation) => {
compilation.hooks.afterOptimizeChunkModules.tap(
'GojiNohoistWebpackPlugin',
// @ts-ignore
// @ts-expect-error
(chunks: Set<webpack.Chunk>) => {
const { chunkGraph } = compilation;
// clean up useless chunks to prevent these temp files to be emitted
Expand Down
4 changes: 2 additions & 2 deletions packages/webpack-plugin/src/plugins/shim/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ const unpatchedGlobalVariables = {

// error objects
Error: typeof Error === 'undefined' ? undefined : Error,
// @ts-ignore
// @ts-expect-error
// eslint-disable-next-line no-undef
AggregateError: typeof AggregateError === 'undefined' ? undefined : AggregateError,
EvalError: typeof EvalError === 'undefined' ? undefined : EvalError,
// @ts-ignore
// @ts-expect-error
// eslint-disable-next-line no-undef
InternalError: typeof InternalError === 'undefined' ? undefined : InternalError,
RangeError: typeof RangeError === 'undefined' ? undefined : RangeError,
Expand Down
Loading

0 comments on commit 65a0c74

Please sign in to comment.