Skip to content

Commit 072b24b

Browse files
committed
update eslint to 9.x and use new flat config format with security rules
1 parent 49dd266 commit 072b24b

164 files changed

Lines changed: 1716 additions & 524 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

apps/E2E/.eslintrc.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

apps/E2E/eslint.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const baseConfig = require('@fluentui-react-native/eslint-config-rules');
2+
3+
module.exports = baseConfig;

apps/component-generator/component-templates/ComponentTemplate/.eslintrc.js

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const baseConfig = require('@fluentui-react-native/eslint-config-rules');
2+
3+
module.exports = baseConfig;

apps/fluent-tester/.eslintrc.js

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const baseConfig = require('@fluentui-react-native/eslint-config-rules');
2+
3+
module.exports = baseConfig;

apps/win32/.eslintrc.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

apps/win32/eslint.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const baseConfig = require('@fluentui-react-native/eslint-config-rules');
2+
3+
module.exports = baseConfig;

convert-eslint-configs.js

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
#!/usr/bin/env node
2+
3+
const { execSync } = require('child_process');
4+
const fs = require('fs');
5+
const path = require('path');
6+
7+
// Find all .eslintrc.js files (excluding node_modules)
8+
const findEslintrcFiles = () => {
9+
const command = 'find . -name ".eslintrc.js" -type f -not -path "./node_modules/*"';
10+
const output = execSync(command, { encoding: 'utf8' });
11+
return output
12+
.trim()
13+
.split('\n')
14+
.filter((line) => line.trim() !== '');
15+
};
16+
17+
// Convert legacy config to flat config
18+
const convertToFlatConfig = (legacyConfig) => {
19+
const config = [];
20+
21+
// Base configuration
22+
const baseConfig = {};
23+
24+
// Handle extends
25+
if (legacyConfig.extends) {
26+
// For now, we'll add a comment about the extends
27+
baseConfig.extends = legacyConfig.extends;
28+
}
29+
30+
// Handle parser options
31+
if (legacyConfig.parserOptions) {
32+
baseConfig.languageOptions = {
33+
parserOptions: legacyConfig.parserOptions,
34+
};
35+
}
36+
37+
// Handle plugins
38+
if (legacyConfig.plugins) {
39+
baseConfig.plugins = legacyConfig.plugins;
40+
}
41+
42+
// Handle rules
43+
if (legacyConfig.rules) {
44+
baseConfig.rules = legacyConfig.rules;
45+
}
46+
47+
// Handle env
48+
if (legacyConfig.env) {
49+
if (!baseConfig.languageOptions) {
50+
baseConfig.languageOptions = {};
51+
}
52+
baseConfig.languageOptions.globals = legacyConfig.env;
53+
}
54+
55+
config.push(baseConfig);
56+
57+
// Handle overrides
58+
if (legacyConfig.overrides) {
59+
legacyConfig.overrides.forEach((override) => {
60+
const overrideConfig = {};
61+
62+
if (override.files) {
63+
overrideConfig.files = override.files;
64+
}
65+
66+
if (override.excludedFiles) {
67+
overrideConfig.ignores = override.excludedFiles;
68+
}
69+
70+
if (override.rules) {
71+
overrideConfig.rules = override.rules;
72+
}
73+
74+
if (override.parserOptions) {
75+
overrideConfig.languageOptions = {
76+
parserOptions: override.parserOptions,
77+
};
78+
}
79+
80+
if (override.plugins) {
81+
overrideConfig.plugins = override.plugins;
82+
}
83+
84+
if (override.env) {
85+
if (!overrideConfig.languageOptions) {
86+
overrideConfig.languageOptions = {};
87+
}
88+
overrideConfig.languageOptions.globals = override.env;
89+
}
90+
91+
config.push(overrideConfig);
92+
});
93+
}
94+
95+
return config;
96+
};
97+
98+
// Generate flat config file content
99+
const generateFlatConfigContent = (flatConfig) => {
100+
let content = '';
101+
102+
// Check if any config has extends
103+
const hasExtends = flatConfig.some((config) => config.extends);
104+
105+
if (hasExtends) {
106+
// For files that extend @fluentui-react-native/eslint-config-rules
107+
const extendsConfig = flatConfig.find((config) => config.extends);
108+
if (extendsConfig.extends.includes('@fluentui-react-native/eslint-config-rules')) {
109+
content += `const baseConfig = require('@fluentui-react-native/eslint-config-rules');\n\n`;
110+
111+
// Check if there are additional rules
112+
const hasAdditionalRules = flatConfig.some((config) => config.rules && Object.keys(config.rules).length > 0);
113+
114+
if (hasAdditionalRules) {
115+
content += `module.exports = [\n`;
116+
content += ` ...baseConfig,\n`;
117+
content += ` {\n`;
118+
119+
const rulesConfig = flatConfig.find((config) => config.rules);
120+
if (rulesConfig.rules) {
121+
content += ` rules: ${JSON.stringify(rulesConfig.rules, null, 6)},\n`;
122+
}
123+
124+
content += ` },\n`;
125+
content += `];\n`;
126+
} else {
127+
content += `module.exports = baseConfig;\n`;
128+
}
129+
} else {
130+
// For other extends configurations, create a more generic structure
131+
content += `module.exports = ${JSON.stringify(flatConfig, null, 2)};\n`;
132+
}
133+
} else {
134+
// No extends, just export the flat config
135+
content += `module.exports = ${JSON.stringify(flatConfig, null, 2)};\n`;
136+
}
137+
138+
return content;
139+
};
140+
141+
// Process a single file
142+
const processFile = (filePath) => {
143+
console.log(`Processing: ${filePath}`);
144+
145+
try {
146+
// Read the existing .eslintrc.js file
147+
const fullPath = path.resolve(filePath);
148+
delete require.cache[fullPath]; // Clear require cache
149+
const legacyConfig = require(fullPath);
150+
151+
// Convert to flat config
152+
const flatConfig = convertToFlatConfig(legacyConfig);
153+
154+
// Generate new content
155+
const newContent = generateFlatConfigContent(flatConfig);
156+
157+
// Write to eslint.config.js
158+
const newFilePath = path.join(path.dirname(filePath), 'eslint.config.js');
159+
fs.writeFileSync(newFilePath, newContent);
160+
161+
// Remove old file
162+
fs.unlinkSync(filePath);
163+
164+
console.log(`✅ Converted ${filePath} to ${newFilePath}`);
165+
} catch (error) {
166+
console.error(`❌ Error processing ${filePath}:`, error.message);
167+
}
168+
};
169+
170+
// Main execution
171+
const main = () => {
172+
console.log('🔄 Finding .eslintrc.js files...');
173+
174+
const eslintrcFiles = findEslintrcFiles();
175+
console.log(`Found ${eslintrcFiles.length} .eslintrc.js files`);
176+
177+
eslintrcFiles.forEach(processFile);
178+
179+
console.log('✅ All files processed!');
180+
};
181+
182+
main();

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"@rnx-kit/lint-lockfile": "^0.1.0",
4444
"babel-jest": "^29.7.0",
4545
"beachball": "^2.20.0",
46-
"eslint": "^8.0.0",
46+
"eslint": "^9.0.0",
4747
"eslint-plugin-import": "^2.27.5",
4848
"lage": "^2.0.0",
4949
"markdown-link-check": "^3.8.7",

0 commit comments

Comments
 (0)