Skip to content
Open
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: 0 additions & 2 deletions .eslintignore

This file was deleted.

54 changes: 0 additions & 54 deletions .eslintrc.js

This file was deleted.

2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ We welcome contributions and feedback! All contributors must sign our [Contribut

## Style

To enforce style rules, we use ESLint. See our [.eslintrc.js](.eslintrc.js) for more information on our specific style rules.
To enforce style rules, we use ESLint. See our [eslint.config.js](eslint.config.js) for more information on our specific style rules.

## License

Expand Down
4 changes: 2 additions & 2 deletions eslint-local-rules/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const __platforms: Platform[] = ['desktop'];

## Configuration

The rules are loaded via `eslint-plugin-local-rules` and configured in `.eslintrc.js`:
The rules are registered as an inline `local-rules` plugin and configured in `eslint.config.js`.

## Adding New Rules

Expand All @@ -64,7 +64,7 @@ The rules are loaded via `eslint-plugin-local-rules` and configured in `.eslintr
'my-rule': require('./my-rule'), // Add here
};
```
4. Enable it in `.eslintrc.js`
4. Enable it in `eslint.config.js` as `'local-rules/my-rule'`

## Testing Rules

Expand Down
2 changes: 1 addition & 1 deletion eslint-local-rules/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* Local ESLint Rules
*
* Custom ESLint rules for the project.
* Loaded by eslint-plugin-local-rules.
* Registered as the inline `local-rules` plugin in eslint.config.js.
*/

module.exports = {
Expand Down
4 changes: 2 additions & 2 deletions eslint-local-rules/require-platform-declaration.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* Ensures that all source files export __platforms with valid platform values.
*
* File exclusions (test files, generated files, etc.) should be configured
* in .eslintrc.js using the 'excludedFiles' option.
* in eslint.config.js using the 'ignores' option.
*
* Valid:
* export const __platforms = ['browser'];
Expand All @@ -33,7 +33,7 @@
* // Not exported as const array
*/

/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable @typescript-eslint/no-require-imports */

const { getValidPlatforms } = require('../scripts/platform-utils');

Expand Down
60 changes: 60 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/* eslint-disable @typescript-eslint/no-require-imports */
const { defineConfig, globalIgnores } = require('eslint/config');
const js = require('@eslint/js');
const globals = require('globals');
const tseslint = require('typescript-eslint');
const localRules = require('./eslint-local-rules');

module.exports = defineConfig(
globalIgnores(['**/*.tests.js', '**/test_data.js']),
js.configs.recommended,
tseslint.configs.recommended,
{
languageOptions: {
// Note: The TS compiler determines what syntax is accepted. We're using TS version 4.x.
// This seems to correspond to "2020" for this setting. In flat config this also
// enables the ES2020 globals (Promise, Atomics, SharedArrayBuffer, ...).
ecmaVersion: 2020,
sourceType: 'module',
globals: {
...globals.browser,
...globals.commonjs,
...globals.node,
},
},
rules: {
'no-prototype-builtins': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-empty-function': 'off',
// These were warnings in @typescript-eslint v5's recommended config; v8 made them errors.
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/no-unused-vars': 'warn',
},
},
{
files: ['**/*.ts'],
rules: {
'@typescript-eslint/explicit-module-boundary-types': 'error',
},
},
{
files: ['lib/**/*.ts', 'src/**/*.ts'],
ignores: [
'**/platform_support.ts',
'**/*.spec.ts',
'**/*.test.ts',
'**/*.tests.ts',
'**/*.test-d.ts',
'**/*.gen.ts',
'**/*.d.ts',
'**/__mocks__/**',
'**/tests/**',
],
plugins: {
'local-rules': { rules: localRules },
},
rules: {
'local-rules/require-platform-declaration': 'error',
},
}
);
4 changes: 2 additions & 2 deletions lib/core/decision_service/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1916,7 +1916,7 @@ describe('DecisionService', () => {

expect(userProfileService?.lookup).toHaveBeenCalledTimes(1);
expect(userProfileService?.lookup).toHaveBeenCalledWith('tester');
expect(userProfileService?.save).not.toHaveBeenCalled;
expect(userProfileService?.save).not.toHaveBeenCalled();
expect(cmabService.getDecision).toHaveBeenCalledTimes(1);

// decide again for the same user, now cmab service should return variation 5001
Expand All @@ -1930,7 +1930,7 @@ describe('DecisionService', () => {

expect(userProfileService?.lookup).toHaveBeenCalledTimes(2);
expect(userProfileService?.lookup).toHaveBeenNthCalledWith(2, 'tester');
expect(userProfileService?.save).not.toHaveBeenCalled;
expect(userProfileService?.save).not.toHaveBeenCalled();
expect(cmabService.getDecision).toHaveBeenCalledTimes(2);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export let isAvailable = true;
let AsyncStorage: AsyncStorageCompat | undefined;

try {
// eslint-disable-next-line @typescript-eslint/no-var-requires
// eslint-disable-next-line @typescript-eslint/no-require-imports
const storage: RawAsyncStorage | undefined = require('@react-native-async-storage/async-storage').default;
AsyncStorage = storage ? ensureMultiGet(storage) : undefined;
} catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion lib/import.react_native/fast-text-encoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export let isAvailable = true;

try {
// Sets a global TextEncoder if there is none; an existing one is kept.
// eslint-disable-next-line @typescript-eslint/no-var-requires
// eslint-disable-next-line @typescript-eslint/no-require-imports
require('fast-text-encoding');
} catch (e) {
isAvailable = false;
Expand Down
2 changes: 1 addition & 1 deletion lib/import.react_native/react-native-get-random-values.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export let isAvailable = true;

try {
// Sets a global crypto.getRandomValues if there is none; an existing one is kept.
// eslint-disable-next-line @typescript-eslint/no-var-requires
// eslint-disable-next-line @typescript-eslint/no-require-imports
require('react-native-get-random-values');
} catch (e) {
isAvailable = false;
Expand Down
2 changes: 1 addition & 1 deletion lib/odp/segment_manager/odp_segment_api_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export class DefaultOdpSegmentApiManager implements OdpSegmentApiManager {
* @returns Response Strongly-typed ODP Response object
*/
private parseSegmentsResponseJson(jsonResponse: string): GraphQLResponse | null {
let jsonObject = {};
let jsonObject: unknown;

try {
jsonObject = JSON.parse(jsonResponse);
Expand Down
6 changes: 2 additions & 4 deletions lib/project_config/optimizely_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,7 @@ export class OptimizelyConfig {
variableIdMap: { [id: string]: FeatureVariable },
featureId: string
): { [key: string]: Variation } {
let variationsMap: { [key: string]: OptimizelyVariation } = {};
variationsMap = variations.reduce((optlyVariationsMap: { [key: string]: OptimizelyVariation }, variation) => {
const variationsMap = variations.reduce((optlyVariationsMap: { [key: string]: OptimizelyVariation }, variation) => {
const variablesMap = OptimizelyConfig.mergeFeatureVariables(
featureIdVariableMap,
variableIdMap,
Expand All @@ -289,8 +288,7 @@ export class OptimizelyConfig {
* @returns {[id: string]: FeatureVariable} FeatureVariables mapped by id
*/
static getVariableIdMap(configObj: ProjectConfig): { [id: string]: FeatureVariable } {
let variablesIdMap: { [id: string]: FeatureVariable } = {};
variablesIdMap = (configObj.featureFlags || []).reduce((resultMap: { [id: string]: FeatureVariable }, feature) => {
const variablesIdMap = (configObj.featureFlags || []).reduce((resultMap: { [id: string]: FeatureVariable }, feature) => {
feature.variables.forEach((variable) => {
resultMap[variable.id] = variable;
});
Expand Down
4 changes: 2 additions & 2 deletions lib/tests/uuid_cjs_shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* shim. Needed because uuid v13+ is ESM-only and cannot be loaded via require().
* Uses Node's built-in crypto.randomUUID() which produces identical RFC 4122 v4 UUIDs.
*/
const Module = require('module'); // eslint-disable-line @typescript-eslint/no-var-requires
const crypto = require('crypto'); // eslint-disable-line @typescript-eslint/no-var-requires
const Module = require('module'); // eslint-disable-line @typescript-eslint/no-require-imports
const crypto = require('crypto'); // eslint-disable-line @typescript-eslint/no-require-imports

const UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;

Expand Down
Loading
Loading