1+ import { existsSync , readFileSync } from 'fs' ;
2+ import { join } from 'path' ;
3+
4+ // Check if Next.js is present in the project
5+ function hasNextJs ( ) : boolean {
6+ try {
7+ const packageJsonPath = join ( process . cwd ( ) , 'package.json' ) ;
8+ if ( ! existsSync ( packageJsonPath ) ) {
9+ return false ;
10+ }
11+
12+ const packageJsonContent = readFileSync ( packageJsonPath , 'utf8' ) ;
13+ const packageJson = JSON . parse ( packageJsonContent ) as {
14+ dependencies ?: Record < string , string > ;
15+ devDependencies ?: Record < string , string > ;
16+ } ;
17+ const dependencies = { ...packageJson . dependencies , ...packageJson . devDependencies } ;
18+
19+ return 'next' in dependencies ;
20+ } catch {
21+ return false ;
22+ }
23+ }
24+
125export default [
226 {
327 rules : {
@@ -13,18 +37,22 @@ export default [
1337 'react/jsx-uses-vars' : 'error' ,
1438 '@typescript-eslint/no-unsafe-member-access' : 'off' ,
1539 '@typescript-eslint/no-unsafe-assignment' : 'off' ,
16- 'no-restricted-imports' : [
17- 'warn' ,
18- {
19- paths : [
20- {
21- name : 'react-intl' ,
22- message :
23- 'Use next-intl instead of react-intl. Docs: https://next-intl-docs.vercel.app/ | ADR: https://www.notion.so/leather-yard-6b5/ADR-Next-intl-et-internationalisation-d-une-app-Next-17da97006602800bafd9cf4ebdfde508' ,
24- } ,
25- ] ,
26- } ,
27- ] ,
40+ ...( hasNextJs ( )
41+ ? {
42+ 'no-restricted-imports' : [
43+ 'warn' ,
44+ {
45+ paths : [
46+ {
47+ name : 'react-intl' ,
48+ message :
49+ 'Use next-intl instead of react-intl. Docs: https://next-intl-docs.vercel.app/ | ADR: https://www.notion.so/leather-yard-6b5/ADR-Next-intl-et-internationalisation-d-une-app-Next-17da97006602800bafd9cf4ebdfde508' ,
50+ } ,
51+ ] ,
52+ } ,
53+ ] ,
54+ }
55+ : { } ) ,
2856 } ,
2957 } ,
3058] as const ;
0 commit comments