@@ -2876,6 +2876,105 @@ describe("FlatESLint", () => {
28762876 assert . deepStrictEqual ( result , cachedResult , "result should be the same with or without cache" ) ;
28772877 } ) ;
28782878
2879+ // https://github.com/eslint/eslint/issues/13507
2880+ it ( "should not store `usedDeprecatedRules` in the cache file" , async ( ) => {
2881+ cacheFilePath = getFixturePath ( ".eslintcache" ) ;
2882+ doDelete ( cacheFilePath ) ;
2883+ assert ( ! shell . test ( "-f" , cacheFilePath ) , "the cache file already exists and wasn't successfully deleted" ) ;
2884+
2885+ const deprecatedRuleId = "space-in-parens" ;
2886+
2887+ eslint = new FlatESLint ( {
2888+ cwd : path . join ( fixtureDir , ".." ) ,
2889+ overrideConfigFile : true ,
2890+
2891+ // specifying cache true the cache will be created
2892+ cache : true ,
2893+ cacheLocation : cacheFilePath ,
2894+ overrideConfig : {
2895+ rules : {
2896+ [ deprecatedRuleId ] : 2
2897+ }
2898+ }
2899+ } ) ;
2900+
2901+ const filePath = fs . realpathSync ( getFixturePath ( "cache/src" , "test-file.js" ) ) ;
2902+
2903+ /*
2904+ * Run linting on the same file 3 times to cover multiple cases:
2905+ * Run 1: Lint result wasn't already cached.
2906+ * Run 2: Lint result was already cached. The cached lint result is used but the cache is reconciled before the run ends.
2907+ * Run 3: Lint result was already cached. The cached lint result was being used throughout the previous run, so possible
2908+ * mutations in the previous run that occured after the cache was reconciled may have side effects for this run.
2909+ */
2910+ for ( let i = 0 ; i < 3 ; i ++ ) {
2911+ const [ result ] = await eslint . lintFiles ( [ filePath ] ) ;
2912+
2913+ assert (
2914+ result . usedDeprecatedRules && result . usedDeprecatedRules . some ( rule => rule . ruleId === deprecatedRuleId ) ,
2915+ "the deprecated rule should have been in result.usedDeprecatedRules"
2916+ ) ;
2917+
2918+ assert ( shell . test ( "-f" , cacheFilePath ) , "the cache for eslint should have been created" ) ;
2919+
2920+ const fileCache = fCache . create ( cacheFilePath ) ;
2921+ const descriptor = fileCache . getFileDescriptor ( filePath ) ;
2922+
2923+ assert ( typeof descriptor === "object" , "an entry for the file should have been in the cache file" ) ;
2924+ assert ( typeof descriptor . meta . results === "object" , "lint result for the file should have been in its cache entry in the cache file" ) ;
2925+ assert ( typeof descriptor . meta . results . usedDeprecatedRules === "undefined" , "lint result in the cache file contains `usedDeprecatedRules`" ) ;
2926+ }
2927+
2928+ } ) ;
2929+
2930+ // https://github.com/eslint/eslint/issues/13507
2931+ it ( "should store `source` as `null` in the cache file if the lint result has `source` property" , async ( ) => {
2932+ cacheFilePath = getFixturePath ( ".eslintcache" ) ;
2933+ doDelete ( cacheFilePath ) ;
2934+ assert ( ! shell . test ( "-f" , cacheFilePath ) , "the cache file already exists and wasn't successfully deleted" ) ;
2935+
2936+ eslint = new FlatESLint ( {
2937+ cwd : path . join ( fixtureDir , ".." ) ,
2938+ overrideConfigFile : true ,
2939+
2940+ // specifying cache true the cache will be created
2941+ cache : true ,
2942+ cacheLocation : cacheFilePath ,
2943+ overrideConfig : {
2944+ rules : {
2945+ "no-unused-vars" : 2
2946+ }
2947+ }
2948+ } ) ;
2949+
2950+ const filePath = fs . realpathSync ( getFixturePath ( "cache/src" , "fail-file.js" ) ) ;
2951+
2952+ /*
2953+ * Run linting on the same file 3 times to cover multiple cases:
2954+ * Run 1: Lint result wasn't already cached.
2955+ * Run 2: Lint result was already cached. The cached lint result is used but the cache is reconciled before the run ends.
2956+ * Run 3: Lint result was already cached. The cached lint result was being used throughout the previous run, so possible
2957+ * mutations in the previous run that occured after the cache was reconciled may have side effects for this run.
2958+ */
2959+ for ( let i = 0 ; i < 3 ; i ++ ) {
2960+ const [ result ] = await eslint . lintFiles ( [ filePath ] ) ;
2961+
2962+ assert ( typeof result . source === "string" , "the result should have contained the `source` property" ) ;
2963+
2964+ assert ( shell . test ( "-f" , cacheFilePath ) , "the cache for eslint should have been created" ) ;
2965+
2966+ const fileCache = fCache . create ( cacheFilePath ) ;
2967+ const descriptor = fileCache . getFileDescriptor ( filePath ) ;
2968+
2969+ assert ( typeof descriptor === "object" , "an entry for the file should have been in the cache file" ) ;
2970+ assert ( typeof descriptor . meta . results === "object" , "lint result for the file should have been in its cache entry in the cache file" ) ;
2971+
2972+ // if the lint result contains `source`, it should be stored as `null` in the cache file
2973+ assert . strictEqual ( descriptor . meta . results . source , null , "lint result in the cache file contains non-null `source`" ) ;
2974+ }
2975+
2976+ } ) ;
2977+
28792978 describe ( "cacheStrategy" , ( ) => {
28802979 it ( "should detect changes using a file's modification time when set to 'metadata'" , async ( ) => {
28812980 cacheFilePath = getFixturePath ( ".eslintcache" ) ;
0 commit comments