Skip to content

Commit 757edac

Browse files
committed
core: fix match poistion for python
1 parent 085187a commit 757edac

File tree

15 files changed

+68
-195
lines changed

15 files changed

+68
-195
lines changed

.eslintrc.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = {
22
parser: '@typescript-eslint/parser',
3-
plugins: ['@typescript-eslint', 'node', 'prettier'],
3+
plugins: ['@typescript-eslint', 'node', 'prettier', '@codeque'],
44
extends: [
55
'eslint:recommended',
66
'plugin:@typescript-eslint/recommended',
@@ -58,5 +58,13 @@ module.exports = {
5858
next: '*',
5959
}, // padding after multiline-expression
6060
],
61+
'@codeque/error': [
62+
'error',
63+
[
64+
{
65+
query: 'console.log()',
66+
},
67+
],
68+
],
6169
},
6270
}

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,8 @@
3232
"checks": "yarn typecheck && yarn lint && yarn test",
3333
"postinstall": "node fix-framer-motion.js",
3434
"syncReadmes": "node ./syncReadmes.js"
35+
},
36+
"dependencies": {
37+
"@codeque/eslint-plugin": "^0.1.1"
3538
}
3639
}

packages/cli/src/dev.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @codeque/error */
12
import {
23
getMode,
34
Mode,

packages/core/__tests__/Python/matchCodePatterns/basic.test.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { searchInStrings } from '../../../src/searchInStrings'
2-
import { getParserSettings } from '../../utils'
2+
import { getParserSettings, compareCode } from '../../utils'
33

44
describe('Basic queries', () => {
55
beforeAll(async () => {
@@ -118,8 +118,17 @@ describe('Basic queries', () => {
118118
expect(errors).toHaveLength(0)
119119
expect(matches.length).toBe(1)
120120

121-
expect(matches[0].aliases.identifierAliasesMap['refPrint'].aliasValue).toBe(
121+
const match = matches[0]
122+
123+
expect(match.aliases.identifierAliasesMap['refPrint'].aliasValue).toBe(
122124
'print',
123125
)
126+
127+
expect(compareCode(fileContent, match.code)).toBe(true)
128+
129+
expect(match.loc).toStrictEqual({
130+
start: { line: 2, column: 6, index: 7 },
131+
end: { line: 7, column: 15, index: 131 },
132+
})
124133
})
125134
})

packages/core/src/parserSettings/python/settings.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ const programNodeAndBlockNodeUtils: ProgramNodeAndBlockNodeUtils = {
9999
const getNodePosition: ParserSettings['getNodePosition'] = (
100100
node: PoorNodeType,
101101
) => ({
102-
start: ((node?.loc as any)?.startIndex as number) ?? 0,
103-
end: ((node?.loc as any)?.endIndex as number) ?? 0,
102+
start: ((node?.loc as any)?.start?.index as number) ?? 0,
103+
end: ((node?.loc as any)?.end?.index as number) ?? 0,
104104
loc: node.loc as unknown as Location,
105105
})
106106

@@ -181,5 +181,9 @@ export default pythonParser
181181

182182
/**
183183
* TODOs:
184-
* Check how types structure is represented and whether our fields cache is breaking the types matching
184+
* - Check how types structure is represented and whether our fields cache is breaking the types matching
185+
* - Support string interpolation `f"project:{self.project_id}:rules"`
186+
* - We need to extract string literals and interpolated expressions to node
187+
* - support detecting python in search from selection
188+
* -
185189
*/

packages/core/src/searchMultiThread.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,12 @@ export const searchMultiThread = async ({
9292
})
9393
resolve(results)
9494
} catch (e) {
95-
reject(
95+
const error = new Error(
9696
'Search on main thread failed with error ' + (e as Error).message,
9797
)
98+
error.stack = (e as Error)?.stack
99+
100+
reject(error)
98101
}
99102
}, 0)
100103
} else {

packages/core/src/searchStages/matchStringOrIdentifierAliases.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,6 @@ export const matchStringOrIdentifierAliases = ({
9292
)
9393

9494
if (wildcardValuesExtractionMatch === null) {
95-
console.log(
96-
'wildcardValuesExtractionRegex',
97-
wildcardValuesExtractionRegex,
98-
)
99-
100-
console.log('fileNodeIdentifierName', fileNodeIdentifierName)
10195
throw new Error(
10296
'Wildcard alias extraction RegExp did not match, thus it was build incorrectly.',
10397
)

packages/core/src/searchStages/searchAst.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export const searchAst = (
4545

4646
return queryCode.substring(pos.start, pos.end)
4747
} catch {
48-
console.log('Failed getting position for node', node)
48+
console.error('Failed getting position for node', node)
4949
}
5050

5151
return ''

packages/eslint/src/lintCode.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,19 @@ let filteringFilePathsTime = 0
3333
const searchTimeForQueries = {} as Record<string, number>
3434

3535
process.on('beforeExit', () => {
36+
const print = console.log
3637
const shouldPrintMetric = process.env.CODEQUE_DEBUG === 'true'
3738

3839
if (shouldPrintMetric) {
39-
console.log('\nCodeQue debug metrics:\n')
40-
console.log('preparationTime', preparationTime)
41-
console.log('shallowSearchTime', shallowSearchTime)
42-
console.log('preparingVisitorsTime', preparingVisitorsTime)
43-
console.log('preparingQueriesTime', preparingQueriesTime)
44-
console.log('filteringFilePathsTime', filteringFilePathsTime)
45-
console.log('searchTimeForQueries', searchTimeForQueries)
46-
console.log('')
47-
console.log('Telemetry is', telemetryDisabled ? 'disabled' : 'enabled')
40+
print('\nCodeQue debug metrics:\n')
41+
print('preparationTime', preparationTime)
42+
print('shallowSearchTime', shallowSearchTime)
43+
print('preparingVisitorsTime', preparingVisitorsTime)
44+
print('preparingQueriesTime', preparingQueriesTime)
45+
print('filteringFilePathsTime', filteringFilePathsTime)
46+
print('searchTimeForQueries', searchTimeForQueries)
47+
print('')
48+
print('Telemetry is', telemetryDisabled ? 'disabled' : 'enabled')
4849
}
4950
})
5051

packages/vscode/src/EventBus.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,11 @@ export class EventBus {
108108
data?: EventTypes[T],
109109
dispatchThroughTransports = true,
110110
) => {
111-
console.log(`dispatch:${this.env}`, eventType, data)
112-
113111
try {
114112
await Promise.all(
115113
this.listeners[eventType].map((callback) => callback(data)),
116114
)
117115
} catch (e) {
118-
console.log(this.env, 'Dispatch error')
119116
console.error(this.env, 'internal dispatch error', e)
120117
}
121118

@@ -139,8 +136,6 @@ export class EventBus {
139136
}),
140137
)
141138
} catch (e) {
142-
console.log(this.env, 'Dispatch transports error')
143-
144139
console.error(
145140
this.env,
146141
'transports dispatch error',

0 commit comments

Comments
 (0)