diff --git a/CHANGELOG.md b/CHANGELOG.md index ef48ce1f..2c7eea28 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ ## Master +## 0.4.5 - Think about testing + +- Bump dependencies +- Parse `jest.requireActual` as a direct dependency + ## 0.4.4 - Bump dependencies - Replace `greenkeeper` with `renovate` diff --git a/package.json b/package.json index 2af41e56..29249c90 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "stricter", - "version": "0.4.4", + "version": "0.4.5", "description": "A project-wide js-linting tool", "files": [ "LICENSE", @@ -87,7 +87,7 @@ "@babel/core": "^7.11.6", "@babel/parser": "^7.11.5", "@wojtekmaj/babylon-walk": "2.0.0", - "ajv": "^6.12.2", + "ajv": "^6.12.5", "ansi-colors": "^4.1.1", "app-root-path": "^3.0.0", "debug": "^4.1.1", @@ -103,7 +103,7 @@ "wrap-ansi": "^7.0.0", "xml-escape": "^1.1.0", "xxhashjs": "^0.2.2", - "yargs": "^15.3.1" + "yargs": "^16.0.3" }, "engines": { "node": ">=10" diff --git a/src/file-processor/parse-imports.test.ts b/src/file-processor/parse-imports.test.ts index 4cd86a72..44861e0d 100644 --- a/src/file-processor/parse-imports.test.ts +++ b/src/file-processor/parse-imports.test.ts @@ -111,4 +111,18 @@ describe('resolveImport', () => { expect(result.staticImports).toEqual(['test-file1']); expect(result.dynamicImports).toEqual([]); }); + + it('should count jest.requireActual', () => { + const result = parseImports( + parse( + ` + const test1 = jest.requireActual('test-file1'); + `, + 'filePath', + ), + ); + + expect(result.staticImports).toEqual([]); + expect(result.dynamicImports).toEqual(['test-file1']); + }); }); diff --git a/src/file-processor/parse-imports.ts b/src/file-processor/parse-imports.ts index e50e435f..9c1658ae 100644 --- a/src/file-processor/parse-imports.ts +++ b/src/file-processor/parse-imports.ts @@ -12,6 +12,7 @@ import type { Identifier, Node, StringLiteral, + MemberExpression, } from 'babel-types'; import type { ParsedImportsResult } from '../types'; @@ -48,18 +49,31 @@ export const parseImports = (ast: NodeTypes): ParsedImportsResult => { }, CallExpression(node: NodeTypes, state: ParsedImportsResult) { const casted = node as CallExpression; + const callee: Node | Identifier | MemberExpression = casted.callee; - const callee: Node | Identifier = casted.callee; + if (!callee) { + return; + } - if ( - callee && - (callee.type === 'Import' || - (callee.type === 'Identifier' && - (callee as Identifier).name === 'require')) && + const isFirstArgumentString = casted.arguments && casted.arguments.length > 0 && - casted.arguments[0].type === 'StringLiteral' - ) { + casted.arguments[0].type === 'StringLiteral'; + + if (!isFirstArgumentString) { + return; + } + + const isImportCall = callee.type === 'Import'; + const isRequireCall = + callee.type === 'Identifier' && (callee as Identifier).name === 'require'; + + const isJestRequireActualCall = + callee.type === 'MemberExpression' && + ((callee as MemberExpression).object as Identifier).name === 'jest' && + ((callee as MemberExpression).property as Identifier).name === 'requireActual'; + + if (isRequireCall || isImportCall || isJestRequireActualCall) { state.dynamicImports.push((casted.arguments[0] as StringLiteral).value); } }, diff --git a/yarn.lock b/yarn.lock index ebf9d187..61423935 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1439,10 +1439,10 @@ acorn@^7.1.1, acorn@^7.4.0: resolved "https://registry.yarnpkg.com/acorn/-/acorn-7.4.0.tgz#e1ad486e6c54501634c6c397c5c121daa383607c" integrity sha512-+G7P8jJmCHr+S+cLfQxygbWhXy+8YTVGzAkpEbcLo2mLoL7tij/VG41QSHACSf5QgYRhMZYHuNc6drJaO0Da+w== -ajv@^6.10.0, ajv@^6.10.2, ajv@^6.12.2, ajv@^6.12.4, ajv@^6.5.5: - version "6.12.4" - resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.12.4.tgz#0614facc4522127fa713445c6bfd3ebd376e2234" - integrity sha512-eienB2c9qVQs2KWexhkrdMLVDoIQCz5KSeLxwg9Lzk4DOfBtIK9PQwwufcsn1jjGuf9WZmqPMbGxOzfcuphJCQ== +ajv@^6.10.0, ajv@^6.10.2, ajv@^6.12.2, ajv@^6.12.4, ajv@^6.12.5, ajv@^6.5.5: + version "6.12.5" + resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.12.5.tgz#19b0e8bae8f476e5ba666300387775fb1a00a4da" + integrity sha512-lRF8RORchjpKG50/WFf8xmg7sgCLFiYNNnqdKflk63whMQcWR5ngGjiSXkL9bjxy6B2npOK2HSMN49jEBMSkag== dependencies: fast-deep-equal "^3.1.1" fast-json-stable-stringify "^2.0.0" @@ -1873,6 +1873,15 @@ cliui@^6.0.0: strip-ansi "^6.0.0" wrap-ansi "^6.2.0" +cliui@^7.0.0: + version "7.0.1" + resolved "https://registry.yarnpkg.com/cliui/-/cliui-7.0.1.tgz#a4cb67aad45cd83d8d05128fc9f4d8fbb887e6b3" + integrity sha512-rcvHOWyGyid6I1WjT/3NatKj2kDt9OdSHSXpyLXaMWFbKpGACNW8pRhhdPUq9MWUOdwn8Rz9AVETjF4105rZZQ== + dependencies: + string-width "^4.2.0" + strip-ansi "^6.0.0" + wrap-ansi "^7.0.0" + co@^4.6.0: version "4.6.0" resolved "https://registry.yarnpkg.com/co/-/co-4.6.0.tgz#6ea6bdf3d853ae54ccb8e47bfa0bf3f9031fb184" @@ -2242,6 +2251,11 @@ error-ex@^1.3.1: dependencies: is-arrayish "^0.2.1" +escalade@^3.0.2: + version "3.0.2" + resolved "https://registry.yarnpkg.com/escalade/-/escalade-3.0.2.tgz#6a580d70edb87880f22b4c91d0d56078df6962c4" + integrity sha512-gPYAU37hYCUhW5euPeR+Y74F7BL+IBsV93j5cvGriSaD1aG6MGsqsV1yamRdrWrb2j3aiZvb0X+UBOWpx3JWtQ== + escape-string-regexp@^1.0.5: version "1.0.5" resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" @@ -2689,7 +2703,7 @@ gensync@^1.0.0-beta.1: resolved "https://registry.yarnpkg.com/gensync/-/gensync-1.0.0-beta.1.tgz#58f4361ff987e5ff6e1e7a210827aa371eaac269" integrity sha512-r8EC6NO1sngH/zdD9fiRDLdcgnbayXah+mLgManTaIZJqEC1MZstmnox8KpnI2/fxQwrp5OpCOYWLp4rBl4Jcg== -get-caller-file@^2.0.1: +get-caller-file@^2.0.1, get-caller-file@^2.0.5: version "2.0.5" resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-2.0.5.tgz#4f94412a82db32f36e3b0b9741f8a97feb031f7e" integrity sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg== @@ -5626,6 +5640,11 @@ y18n@^4.0.0: resolved "https://registry.yarnpkg.com/y18n/-/y18n-4.0.0.tgz#95ef94f85ecc81d007c264e190a120f0a3c8566b" integrity sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w== +y18n@^5.0.1: + version "5.0.1" + resolved "https://registry.yarnpkg.com/y18n/-/y18n-5.0.1.tgz#1ad2a7eddfa8bce7caa2e1f6b5da96c39d99d571" + integrity sha512-/jJ831jEs4vGDbYPQp4yGKDYPSCCEQ45uZWJHE1AoYBzqdZi8+LDWas0z4HrmJXmKdpFsTiowSHXdxyFhpmdMg== + yargs-parser@^13.1.2: version "13.1.2" resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-13.1.2.tgz#130f09702ebaeef2650d54ce6e3e5706f7a4fb38" @@ -5642,6 +5661,11 @@ yargs-parser@^18.1.2: camelcase "^5.0.0" decamelize "^1.2.0" +yargs-parser@^20.0.0: + version "20.0.0" + resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-20.0.0.tgz#c65a1daaa977ad63cebdd52159147b789a4e19a9" + integrity sha512-8eblPHTL7ZWRkyjIZJjnGf+TijiKJSwA24svzLRVvtgoi/RZiKa9fFQTrlx0OKLnyHSdt/enrdadji6WFfESVA== + yargs@^13.3.0: version "13.3.2" resolved "https://registry.yarnpkg.com/yargs/-/yargs-13.3.2.tgz#ad7ffefec1aa59565ac915f82dccb38a9c31a2dd" @@ -5675,6 +5699,19 @@ yargs@^15.3.1, yargs@^15.4.1: y18n "^4.0.0" yargs-parser "^18.1.2" +yargs@^16.0.3: + version "16.0.3" + resolved "https://registry.yarnpkg.com/yargs/-/yargs-16.0.3.tgz#7a919b9e43c90f80d4a142a89795e85399a7e54c" + integrity sha512-6+nLw8xa9uK1BOEOykaiYAJVh6/CjxWXK/q9b5FpRgNslt8s22F2xMBqVIKgCRjNgGvGPBy8Vog7WN7yh4amtA== + dependencies: + cliui "^7.0.0" + escalade "^3.0.2" + get-caller-file "^2.0.5" + require-directory "^2.1.1" + string-width "^4.2.0" + y18n "^5.0.1" + yargs-parser "^20.0.0" + yn@3.1.1: version "3.1.1" resolved "https://registry.yarnpkg.com/yn/-/yn-3.1.1.tgz#1e87401a09d767c1d5eab26a6e4c185182d2eb50"