Tooling, Testing & Linting Flashcards

TypeScript with ESLint & Prettier Unit Testing with Jest and ts-jest Typing Mocks Source Maps and Debugging (41 cards)

1
Q

What is ESLint?

A

ESLint is a static code analysis tool for identifying problematic patterns in JavaScript/TypeScript code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is Prettier?

A

Prettier is an opinionated code formatter that enforces consistent style by parsing and re-printing code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Why use ESLint with TypeScript?

A

ESLint helps catch bugs and enforce best practices by analyzing TypeScript syntax and types using plugins like @typescript-eslint.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is ts-jest?

A

ts-jest is a Jest transformer that allows TypeScript code to be tested directly using Jest without a separate compilation step.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are typing mocks in Jest?

A

Typing mocks refers to giving proper TypeScript types to mocked functions or modules, avoiding ‘any’ and ensuring type safety.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are source maps in TypeScript?

A

Source maps map compiled JavaScript back to the original TypeScript source for easier debugging.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the advantage of using ESLint and Prettier together?

A

ESLint catches code quality issues, while Prettier ensures consistent formatting—together they improve code readability and maintainability.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a disadvantage of integrating ESLint, Prettier, and TypeScript?

A

It requires additional setup, and configuration conflicts may arise if not carefully managed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a best practice when using ESLint with TypeScript?

A

Use the @typescript-eslint plugin and extend recommended configs to catch both JS and TS issues.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a use case for ts-jest?

A

Unit testing TypeScript code without compiling manually, enabling fast feedback and tight integration with Jest features.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is a performance implication of ts-jest?

A

While ts-jest simplifies testing, it can slow down test execution due to on-the-fly transpilation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the architectural impact of using ESLint and Prettier?

A

Enforces consistent coding standards and prevents code smell across large codebases or teams.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is a real-world tradeoff with strict lint rules?

A

Overly strict rules may hinder developer productivity or require excessive boilerplate suppression.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What’s a common interview question around ts-jest?

A

How do you configure Jest to work with TypeScript using ts-jest?

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is a gotcha when mocking TypeScript modules?

A

Mocked modules may lose type safety unless properly typed with jest.Mocked or manual typings.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How do source maps help debugging?

A

They allow debuggers to show TypeScript code instead of transpiled JavaScript when setting breakpoints or reading stack traces.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is a common ESLint rule for TypeScript?

A

@typescript-eslint/no-explicit-any warns against using the ‘any’ type, encouraging stronger typing.

18
Q

What is the advantage of using Prettier over manual formatting?

A

It automates formatting decisions, removing debates and making code reviews more focused on logic.

19
Q

What is the benefit of typing mocks in tests?

A

Maintains type safety in unit tests, reducing runtime bugs and improving test readability.

20
Q

What is a best practice when mocking TypeScript classes?

A

Use interfaces or utility types like jest.Mocked<T> to retain type integrity.</T>

21
Q

What’s a potential issue with source maps in production?

A

They may expose original source code if not excluded from public builds, posing a security risk.

22
Q

What is a good way to integrate ESLint and Prettier?

A

Use eslint-config-prettier to turn off ESLint rules that conflict with Prettier, and run both via scripts or pre-commit hooks.

23
Q

What’s the impact of tooling on team collaboration?

A

Consistent linting and formatting prevent merge conflicts and ensure uniform code across contributors.

24
Q

What’s an example of a Jest mock with types?

A

jest.mock(‘./api’); const mockedApi = jest.mocked(api);

25
What does the 'sourceMap' compiler option do?
It generates .map files that allow mapping transpiled code to the original TypeScript source during debugging.
26
What is a best practice for maintaining source maps?
Only enable source maps for development and debugging builds, not in production.
27
What is a tradeoff of using strict ts-jest settings?
Improves type safety but may require more verbose setup and configuration in test files.
28
What’s a disadvantage of using Jest with large TS projects?
Startup time can increase, and you may need to optimize with isolatedModules or skipLibCheck.
29
What’s the architectural implication of using strict linting rules?
They enforce clean code principles and reduce technical debt over time.
30
What’s a benefit of running ESLint and Prettier in CI/CD?
It guarantees code quality and formatting before code is merged or deployed.
31
What is a common mistake with ts-jest config?
Forgetting to set 'preset: ts-jest' or misconfiguring tsconfig for test environments.
32
What is a potential gotcha when combining ESLint and Prettier?
Conflicting rules can lead to redundant or contradictory formatting unless properly integrated.
33
What does 'jest.mocked()' do?
It provides type-safe access to mocked modules/functions when using TypeScript with Jest.
34
What is the role of @typescript-eslint/parser?
It allows ESLint to parse TypeScript code so that rules can be applied correctly.
35
What is the role of @typescript-eslint/eslint-plugin?
It provides TypeScript-specific linting rules for ESLint.
36
How can you debug Jest tests in VSCode?
Use a launch config with 'jest' and enable 'sourceMaps' in tsconfig to debug TypeScript test files.
37
What is a common interview question about ESLint in TypeScript?
How do you set up a TypeScript project with ESLint and Prettier to ensure code quality?
38
What’s a good way to enforce formatting on commit?
Use tools like Husky + lint-staged to run ESLint and Prettier automatically before commits.
39
What is the benefit of integrating type-aware linting?
It provides smarter rules that understand TypeScript types, catching errors plain ESLint can’t.
40
Why might tests fail when using source maps incorrectly?
Stack traces may not align with actual code, making it hard to trace bugs or test issues.
41
What is a drawback of using mocks in every test?
It may hide integration issues and overfit tests to implementation details rather than behavior.