Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update unicorn preset to 56, update prettier to v3 #248

Merged
merged 5 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ jobs:
- name: Restore target
uses: actions/download-artifact@v4
with:
name: artifact-${{ github.run_id }}
name: artifact-${{ github.run_id }}-target
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
Expand Down
12 changes: 6 additions & 6 deletions packages/eslint-config-qiwi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
"@typescript-eslint/parser": "^7.16.0",
"eslint-plugin-react": "^7.37.1",
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-sonarjs": "^2.0.0",
"eslint-plugin-unicorn": "^47.0.0"
"eslint-plugin-sonarjs": "^2.0.3",
"eslint-plugin-unicorn": "^56.0.0"
},
"peerDependencies": {
"eslint": "^8.0.0",
Expand All @@ -46,11 +46,11 @@
"devDependencies": {
"@qiwi/lint-config-infra": "2.1.1",
"@qiwi/stdstream-snapshot": "^1.2.9",
"@swissquote/crafty-preset-jest": "^1.22.3",
"@types/jest": "^29.5.1",
"@swissquote/crafty-preset-jest": "^1.27.0",
"@types/jest": "^29.5.13",
"eslint": "^8.56.0",
"jest": "^29.5.0",
"ts-jest": "^29.1.0",
"jest": "^29.7.0",
"ts-jest": "^29.2.5",
"typescript": "^5.0.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ exports[`eslint-config-qiwi (JavaScript) config works as expected 1`] = `
4:17 error Do not use useless \`undefined\` unicorn/no-useless-undefined
5:22 error Unnecessary escape character: \\o no-useless-escape
6:18 error Unexpected control character(s) in regular expression: \\x1f no-control-regex
6:18 error Use Unicode escapes instead of hexadecimal escapes unicorn/no-hex-escape
6:18 error Use uppercase characters for the value of the escape sequence unicorn/escape-case
6:18 error Use Unicode escapes instead of hexadecimal escapes unicorn/no-hex-escape
7:29 error Unexpected control character(s) in regular expression: \\x1f no-control-regex
7:29 error Use uppercase characters for the value of the escape sequence unicorn/escape-case
7:29 error Use Unicode escapes instead of hexadecimal escapes unicorn/no-hex-escape
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ exports[`eslint-config-qiwi (TypeScript) config works as expected 1`] = `
8:3 error Unexpected var, use let or const instead no-var
8:7 warning 'pattern1' is assigned a value but never used @typescript-eslint/no-unused-vars
8:18 error Unexpected control character(s) in regular expression: \\x1f no-control-regex
8:18 error Use Unicode escapes instead of hexadecimal escapes unicorn/no-hex-escape
8:18 error Use uppercase characters for the value of the escape sequence unicorn/escape-case
8:18 error Use Unicode escapes instead of hexadecimal escapes unicorn/no-hex-escape
9:3 error Unexpected var, use let or const instead no-var
9:7 warning 'pattern2' is assigned a value but never used @typescript-eslint/no-unused-vars
9:29 error Unexpected control character(s) in regular expression: \\x1f no-control-regex
Expand All @@ -37,8 +37,6 @@ exports[`eslint-config-qiwi (TypeScript) config works as expected 1`] = `
19:5 error This case's code block is the same as the block for the case on line 17 sonarjs/no-duplicated-branches
19:5 error Expected a 'break' statement before 'case' no-fallthrough
27:7 error Do not use the '===' operator to compare against -0 no-compare-neg-zero
28:10 error This number literal will lose precision at runtime @typescript-eslint/no-loss-of-precision
28:10 error Octal literals should not be used no-octal
29:5 error Move function declaration to function body root no-inner-declarations
29:14 warning 'declaration' is defined but never used @typescript-eslint/no-unused-vars
29:28 error Unexpected empty function 'declaration' @typescript-eslint/no-empty-function
Expand All @@ -56,7 +54,7 @@ exports[`eslint-config-qiwi (TypeScript) config works as expected 1`] = `
64:33 error Empty block statement no-empty
67:1 error Read-only global 'window' should not be modified no-global-assign

46 problems (38 errors, 8 warnings)
44 problems (36 errors, 8 warnings)
10 errors and 0 warnings potentially fixable with the \`--fix\` option.",
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const bar = (foo) => {
}

if (sw === -0) {
sw = 071
sw = 0o71
function declaration() { }
}

Expand Down
14 changes: 7 additions & 7 deletions packages/infra/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
"typedoc": "../../node_modules/.bin/typedoc"
},
"devDependencies": {
"@types/jest": "^29.5.1",
"@types/node": "^20.0.0",
"buildstamp": "^3.0.0",
"@types/jest": "^29.5.13",
"@types/node": "^22.7.5",
"buildstamp": "^3.5.0",
"eslint": "^8.39.0",
"eslint-plugin-disable": "^2.0.3",
"jest": "^29.5.0",
"prettier": "^2.8.8",
"typedoc": "^0.26.0",
"typescript": "^5.0.4"
"jest": "^29.7.0",
"prettier": "^3.3.3",
"typedoc": "^0.26.8",
"typescript": "^5.6.3"
},
"license": "MIT",
"repository": {
Expand Down
14 changes: 7 additions & 7 deletions packages/prettier-config-qiwi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@
"author": "QIWI <[email protected]>",
"license": "MIT",
"dependencies": {
"@trivago/prettier-plugin-sort-imports": "^4.1.1"
"@trivago/prettier-plugin-sort-imports": "^4.3.0"
},
"peerDependencies": {
"prettier": "^2.0.0",
"prettier": "^3.0.0",
"typescript": "^5.0.0"
},
"devDependencies": {
"@qiwi/lint-config-infra": "2.1.1",
"@swissquote/crafty-preset-jest": "^1.22.3",
"jest": "^29.5.0",
"prettier": "^2.8.8",
"@swissquote/crafty-preset-jest": "^1.27.0",
"jest": "^29.7.0",
"prettier": "^3.3.3",
"stdstream-snapshot": "^1.2.9",
"ts-jest": "^29.1.0",
"typescript": "^5.0.4"
"ts-jest": "^29.2.5",
"typescript": "^5.6.3"
}
}
1 change: 1 addition & 0 deletions packages/prettier-config-qiwi/src/main/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module.exports = {
trailingComma: 'all',
semi: false,
singleQuote: true,
plugins: ['@trivago/prettier-plugin-sort-imports'],
importOrder: ['^node:', '^react', '^@qiwi/', '^@pijma/', '^[^./]', '^[./]'],
importOrderSeparation: true,
importOrderSortSpecifiers: true,
Expand Down
45 changes: 12 additions & 33 deletions packages/prettier-config-qiwi/src/test/ts/index.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,23 @@
import { execSync } from 'node:child_process'
import {
copyFileSync,
existsSync,
mkdirSync,
readFileSync,
rmdirSync,
} from 'node:fs'
import { resolve } from 'node:path'

import * as cp from 'node:child_process'
import * as fs from 'node:fs'
import * as path from 'node:path'
import * as prettierConfig from '../../main/js'

describe('', () => {
const tmpDir = resolve(__dirname, '../../../../../tmp')

beforeAll(() => {
if (existsSync(tmpDir)) {
rmdirSync(tmpDir, { recursive: true })
}
mkdirSync(tmpDir)
})
const root = path.resolve(__dirname, '../../../../../')
const pkgRoot = path.resolve(root, 'packages/prettier-config-qiwi')
const bin = path.resolve(root, 'node_modules/.bin/prettier')

describe('prettier', () => {
it('prettierConfig', () => {
expect(prettierConfig).toBeDefined()
})

it('formats as expected', async () => {
const configPath = resolve(__dirname, '../../main/js/index.js')

const prettier = resolve(
__dirname,
'../../../../../node_modules/.bin/prettier',
)
const input = resolve(__dirname, '../fixtures/input.ts')
const output = resolve(__dirname, '../fixtures/output.ts')
const temp = resolve(tmpDir, 'index.ts')

copyFileSync(input, temp)

execSync(`${prettier} --config ${configPath} --write ${temp}`)
const configPath = path.resolve(pkgRoot, 'src/main/js/index.js')
const input = path.resolve(pkgRoot, 'src/test/fixtures/input.ts')
const output = path.resolve(pkgRoot, 'src/test/fixtures/output.ts')

expect(readFileSync(temp, 'utf-8')).toBe(readFileSync(output, 'utf-8'))
const result = cp.execSync(`${bin} ${input} --config ${configPath}`).toString()

Check warning

Code scanning / CodeQL

Shell command built from environment values Medium test

This shell command depends on an uncontrolled
absolute path
.
This shell command depends on an uncontrolled
absolute path
.
This shell command depends on an uncontrolled
absolute path
.
This shell command depends on an uncontrolled
absolute path
.
This shell command depends on an uncontrolled
absolute path
.

Copilot Autofix AI about 1 month ago

To fix the problem, we should avoid constructing the shell command as a single string and instead use the cp.execFileSync method, which allows us to pass the command and its arguments separately. This approach prevents the shell from interpreting special characters in the paths.

  1. Replace the cp.execSync call with cp.execFileSync.
  2. Pass the command (bin) and its arguments (input, --config, configPath) as separate parameters to cp.execFileSync.
Suggested changeset 1
packages/prettier-config-qiwi/src/test/ts/index.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/prettier-config-qiwi/src/test/ts/index.ts b/packages/prettier-config-qiwi/src/test/ts/index.ts
--- a/packages/prettier-config-qiwi/src/test/ts/index.ts
+++ b/packages/prettier-config-qiwi/src/test/ts/index.ts
@@ -19,3 +19,3 @@
 
-    const result = cp.execSync(`${bin} ${input} --config ${configPath}`).toString()
+    const result = cp.execFileSync(bin, [input, '--config', configPath]).toString()
     expect(result).toBe(fs.readFileSync(output, 'utf-8'))
EOF
@@ -19,3 +19,3 @@

const result = cp.execSync(`${bin} ${input} --config ${configPath}`).toString()
const result = cp.execFileSync(bin, [input, '--config', configPath]).toString()
expect(result).toBe(fs.readFileSync(output, 'utf-8'))
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
expect(result).toBe(fs.readFileSync(output, 'utf-8'))
})
})
Loading