mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-24 20:26:08 +00:00
Add lint rule for as any and bulk ignore all existing breaks
For #269213 This adds a new eslint rule for `as any` and `<any>({... })`. We'd like to remove almost all of these, however right now the first goal is to prevent them in new code. That's why with this first PR I simply add `eslint-disable` comments for all breaks Trying to get this change in soon after branching off for release to hopefully minimize disruption during debt week work
This commit is contained in:
@@ -20,6 +20,7 @@ const jupyterLanguageToMonacoLanguageMapping = new Map([
|
||||
export function getPreferredLanguage(metadata?: nbformat.INotebookMetadata) {
|
||||
const jupyterLanguage =
|
||||
metadata?.language_info?.name ||
|
||||
// eslint-disable-next-line local/code-no-any-casts
|
||||
(metadata?.kernelspec as any)?.language;
|
||||
|
||||
// Default to python language only if the Python extension is installed.
|
||||
@@ -290,6 +291,7 @@ export function jupyterCellOutputToCellOutput(output: nbformat.IOutput): Noteboo
|
||||
if (fn) {
|
||||
result = fn(output);
|
||||
} else {
|
||||
// eslint-disable-next-line local/code-no-any-casts
|
||||
result = translateDisplayDataOutput(output as any);
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -11,13 +11,18 @@ export function deepClone<T>(obj: T): T {
|
||||
}
|
||||
if (obj instanceof RegExp) {
|
||||
// See https://github.com/microsoft/TypeScript/issues/10990
|
||||
// eslint-disable-next-line local/code-no-any-casts
|
||||
return obj as any;
|
||||
}
|
||||
const result: any = Array.isArray(obj) ? [] : {};
|
||||
// eslint-disable-next-line local/code-no-any-casts
|
||||
Object.keys(<any>obj).forEach((key: string) => {
|
||||
// eslint-disable-next-line local/code-no-any-casts
|
||||
if ((<any>obj)[key] && typeof (<any>obj)[key] === 'object') {
|
||||
// eslint-disable-next-line local/code-no-any-casts
|
||||
result[key] = deepClone((<any>obj)[key]);
|
||||
} else {
|
||||
// eslint-disable-next-line local/code-no-any-casts
|
||||
result[key] = (<any>obj)[key];
|
||||
}
|
||||
});
|
||||
|
||||
@@ -37,6 +37,7 @@ export function sortObjectPropertiesRecursively(obj: any): any {
|
||||
}
|
||||
if (obj !== undefined && obj !== null && typeof obj === 'object' && Object.keys(obj).length > 0) {
|
||||
return (
|
||||
// eslint-disable-next-line local/code-no-any-casts
|
||||
Object.keys(obj)
|
||||
.sort()
|
||||
.reduce<Record<string, any>>((sortedObj, prop) => {
|
||||
@@ -57,6 +58,7 @@ export function getCellMetadata(options: { cell: NotebookCell | NotebookCellData
|
||||
...(cell.metadata ?? {})
|
||||
} satisfies CellMetadata;
|
||||
if (cell.kind === NotebookCellKindMarkup) {
|
||||
// eslint-disable-next-line local/code-no-any-casts
|
||||
delete (metadata as any).execution_count;
|
||||
}
|
||||
return metadata;
|
||||
@@ -398,7 +400,9 @@ export function pruneCell(cell: nbformat.ICell): nbformat.ICell {
|
||||
|
||||
// Remove outputs and execution_count from non code cells
|
||||
if (result.cell_type !== 'code') {
|
||||
// eslint-disable-next-line local/code-no-any-casts
|
||||
delete (<any>result).outputs;
|
||||
// eslint-disable-next-line local/code-no-any-casts
|
||||
delete (<any>result).execution_count;
|
||||
} else {
|
||||
// Clean outputs from code cells
|
||||
|
||||
@@ -37,6 +37,7 @@ suite(`Notebook Model Store Sync`, () => {
|
||||
onWillSaveNotebookDocument = new AsyncEmitter<NotebookDocumentWillSaveEvent>();
|
||||
|
||||
sinon.stub(NotebookEdit, 'updateCellMetadata').callsFake((index, metadata) => {
|
||||
// eslint-disable-next-line local/code-no-any-casts
|
||||
const edit = (NotebookEdit.updateCellMetadata as any).wrappedMethod.call(NotebookEdit, index, metadata);
|
||||
cellMetadataUpdates.push(edit);
|
||||
return edit;
|
||||
@@ -75,6 +76,7 @@ suite(`Notebook Model Store Sync`, () => {
|
||||
test('Adding cell for non Jupyter Notebook will not result in any updates', async () => {
|
||||
sinon.stub(notebook, 'notebookType').get(() => 'some-other-type');
|
||||
const cell: NotebookCell = {
|
||||
// eslint-disable-next-line local/code-no-any-casts
|
||||
document: {} as any,
|
||||
executionSummary: {},
|
||||
index: 0,
|
||||
@@ -104,6 +106,7 @@ suite(`Notebook Model Store Sync`, () => {
|
||||
test('Adding cell to nbformat 4.2 notebook will result in adding empty metadata', async () => {
|
||||
sinon.stub(notebook, 'metadata').get(() => ({ nbformat: 4, nbformat_minor: 2 }));
|
||||
const cell: NotebookCell = {
|
||||
// eslint-disable-next-line local/code-no-any-casts
|
||||
document: {} as any,
|
||||
executionSummary: {},
|
||||
index: 0,
|
||||
@@ -135,6 +138,7 @@ suite(`Notebook Model Store Sync`, () => {
|
||||
test('Added cell will have a cell id if nbformat is 4.5', async () => {
|
||||
sinon.stub(notebook, 'metadata').get(() => ({ nbformat: 4, nbformat_minor: 5 }));
|
||||
const cell: NotebookCell = {
|
||||
// eslint-disable-next-line local/code-no-any-casts
|
||||
document: {} as any,
|
||||
executionSummary: {},
|
||||
index: 0,
|
||||
@@ -169,6 +173,7 @@ suite(`Notebook Model Store Sync`, () => {
|
||||
test('Do not add cell id if one already exists', async () => {
|
||||
sinon.stub(notebook, 'metadata').get(() => ({ nbformat: 4, nbformat_minor: 5 }));
|
||||
const cell: NotebookCell = {
|
||||
// eslint-disable-next-line local/code-no-any-casts
|
||||
document: {} as any,
|
||||
executionSummary: {},
|
||||
index: 0,
|
||||
@@ -205,6 +210,7 @@ suite(`Notebook Model Store Sync`, () => {
|
||||
test('Do not perform any updates if cell id and metadata exists', async () => {
|
||||
sinon.stub(notebook, 'metadata').get(() => ({ nbformat: 4, nbformat_minor: 5 }));
|
||||
const cell: NotebookCell = {
|
||||
// eslint-disable-next-line local/code-no-any-casts
|
||||
document: {} as any,
|
||||
executionSummary: {},
|
||||
index: 0,
|
||||
@@ -242,6 +248,7 @@ suite(`Notebook Model Store Sync`, () => {
|
||||
}
|
||||
}));
|
||||
const cell: NotebookCell = {
|
||||
// eslint-disable-next-line local/code-no-any-casts
|
||||
document: {
|
||||
languageId: 'javascript'
|
||||
} as any,
|
||||
@@ -264,6 +271,7 @@ suite(`Notebook Model Store Sync`, () => {
|
||||
cellChanges: [
|
||||
{
|
||||
cell,
|
||||
// eslint-disable-next-line local/code-no-any-casts
|
||||
document: {
|
||||
languageId: 'javascript'
|
||||
} as any,
|
||||
@@ -292,6 +300,7 @@ suite(`Notebook Model Store Sync`, () => {
|
||||
}
|
||||
}));
|
||||
const cell: NotebookCell = {
|
||||
// eslint-disable-next-line local/code-no-any-casts
|
||||
document: {
|
||||
languageId: 'javascript'
|
||||
} as any,
|
||||
@@ -335,6 +344,7 @@ suite(`Notebook Model Store Sync`, () => {
|
||||
}
|
||||
}));
|
||||
const cell: NotebookCell = {
|
||||
// eslint-disable-next-line local/code-no-any-casts
|
||||
document: {
|
||||
languageId: 'javascript'
|
||||
} as any,
|
||||
@@ -358,6 +368,7 @@ suite(`Notebook Model Store Sync`, () => {
|
||||
cellChanges: [
|
||||
{
|
||||
cell,
|
||||
// eslint-disable-next-line local/code-no-any-casts
|
||||
document: {
|
||||
languageId: 'javascript'
|
||||
} as any,
|
||||
@@ -386,6 +397,7 @@ suite(`Notebook Model Store Sync`, () => {
|
||||
}
|
||||
}));
|
||||
const cell: NotebookCell = {
|
||||
// eslint-disable-next-line local/code-no-any-casts
|
||||
document: {
|
||||
languageId: 'powershell'
|
||||
} as any,
|
||||
@@ -409,6 +421,7 @@ suite(`Notebook Model Store Sync`, () => {
|
||||
cellChanges: [
|
||||
{
|
||||
cell,
|
||||
// eslint-disable-next-line local/code-no-any-casts
|
||||
document: {
|
||||
languageId: 'powershell'
|
||||
} as any,
|
||||
@@ -443,6 +456,7 @@ suite(`Notebook Model Store Sync`, () => {
|
||||
});
|
||||
|
||||
const cell: NotebookCell = {
|
||||
// eslint-disable-next-line local/code-no-any-casts
|
||||
document: {} as any,
|
||||
executionSummary: {},
|
||||
index: 0,
|
||||
|
||||
Reference in New Issue
Block a user