Skip to content

Commit 886aeba

Browse files
authored
refactor(fs): lint rule to avoid node:fs aws#5755
## Problem We want to avoid future unnecessary use of `fs` module and maximize usage of our wrapper fs. Benefits include: - more control over interfacing with fs. - increased web compatibility. - minimizing dependencies. ## Solution - add a lint rule to discourage future imports of `fs`. - leave current uses as exceptions. - Planning follow up PR to migrate some of the easy uses of fs to our wrapper.
1 parent 2172bf9 commit 886aeba

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+54
-50
lines changed

.eslintrc.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,10 @@ module.exports = {
180180
message:
181181
'Avoid fs-extra, use shared/fs/fs.ts. Notify the Toolkit team if your required functionality is not available.',
182182
},
183+
{
184+
name: 'fs',
185+
message: 'Avoid node:fs and use shared/fs/fs.ts when possible.',
186+
},
183187
],
184188
},
185189
],

packages/amazonq/test/unit/codewhisperer/service/securityScanHandler.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
import assert from 'assert'
1818
import sinon from 'sinon'
1919
import * as vscode from 'vscode'
20-
import fs from 'fs'
20+
import fs from 'fs' // eslint-disable-line no-restricted-imports
2121

2222
const mockCodeScanFindings = JSON.stringify([
2323
{

packages/core/scripts/build/generateServiceClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import * as proc from 'child_process'
7-
import * as nodefs from 'fs'
7+
import * as nodefs from 'fs' // eslint-disable-line no-restricted-imports
88
import * as path from 'path'
99

1010
const repoRoot = path.join(process.cwd(), '../../') // root/packages/toolkit -> root/

packages/core/src/amazonq/lsp/lspController.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import * as vscode from 'vscode'
77
import * as path from 'path'
88
import * as crypto from 'crypto'
9-
import { createWriteStream } from 'fs'
9+
import { createWriteStream } from 'fs' // eslint-disable-line no-restricted-imports
1010
import { getLogger } from '../../shared/logger/logger'
1111
import { CurrentWsFolders, collectFilesForIndex } from '../../shared/utilities/workspaceUtils'
1212
import fetch from 'node-fetch'

packages/core/src/amazonqGumby/chat/controller/controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* This class is responsible for responding to UI events by calling
66
* the Gumby extension.
77
*/
8-
import nodefs from 'fs'
8+
import nodefs from 'fs' // eslint-disable-line no-restricted-imports
99
import path from 'path'
1010
import * as vscode from 'vscode'
1111
import { GumbyNamedMessages, Messenger } from './messenger/messenger'

packages/core/src/awsService/accessanalyzer/vue/iamPolicyChecks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import * as vscode from 'vscode'
7-
import * as fs from 'fs'
7+
import * as fs from 'fs' // eslint-disable-line no-restricted-imports
88
import * as path from 'path'
99
import { getLogger, Logger } from '../../../shared/logger'
1010
import { localize } from '../../../shared/utilities/vsCodeUtils'

packages/core/src/awsService/s3/commands/uploadFile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import * as path from 'path'
77
import * as mime from 'mime-types'
88
import * as vscode from 'vscode'
9-
import { statSync } from 'fs'
9+
import { statSync } from 'fs' // eslint-disable-line no-restricted-imports
1010
import { S3 } from 'aws-sdk'
1111
import { getLogger } from '../../../shared/logger'
1212
import { S3Node } from '../explorer/s3Nodes'

packages/core/src/codewhisperer/commands/startTransformByQ.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import * as vscode from 'vscode'
7-
import * as fs from 'fs'
7+
import * as fs from 'fs' // eslint-disable-line no-restricted-imports
88
import * as os from 'os'
99
import path from 'path'
1010
import { getLogger } from '../../shared/logger'

packages/core/src/codewhisperer/service/securityScanHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
import { sleep } from '../../shared/utilities/timeoutUtils'
1717
import * as codewhispererClient from '../client/codewhisperer'
1818
import * as CodeWhispererConstants from '../models/constants'
19-
import { existsSync, statSync, readFileSync } from 'fs'
19+
import { existsSync, statSync, readFileSync } from 'fs' // eslint-disable-line no-restricted-imports
2020
import { RawCodeScanIssue } from '../models/model'
2121
import * as crypto from 'crypto'
2222
import path = require('path')

packages/core/src/codewhisperer/service/transformByQ/transformApiHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55
import * as vscode from 'vscode'
6-
import * as nodefs from 'fs'
6+
import * as nodefs from 'fs' // eslint-disable-line no-restricted-imports
77
import * as path from 'path'
88
import * as os from 'os'
99
import * as codeWhisperer from '../../client/codewhisperer'

0 commit comments

Comments
 (0)