@@ -356,6 +356,63 @@ function getContent(content) {
356356 return null
357357}
358358
359+ // Filter out entries from an array like this:
360+ //
361+ // [
362+ // [relativePath, absolutePath],
363+ // ...
364+ // so it's only the files mentioned in the DIFF_FILES environment
365+ // variable, but only if it's set and present.
366+
367+ // Setting an environment varible called `DIFF_FILES` is optional.
368+ // But if and only if it's set, we will respect it.
369+ // And if it set, turn it into a cleaned up Set so it's made available
370+ // every time we use it.
371+ if ( process . env . DIFF_FILES ) {
372+ // Parse and turn that environment variable string into a set.
373+ // It's faster to do this once and then re-use over and over in the
374+ // .filter() later on.
375+ const only = new Set (
376+ // If the environment variable encodes all the names
377+ // with quotation marks, strip them.
378+ // E.g. Turn `"foo" "bar"` into ['foo', 'bar']
379+ // Note, this assumes no possible file contains a space.
380+ process . env . DIFF_FILES . split ( / \s + / g) . map ( ( name ) => {
381+ if ( / ^ [ ' " ] / . test ( name ) && / [ ' " ] $ / . test ( name ) ) {
382+ return name . slice ( 1 , - 1 )
383+ }
384+ return name
385+ } )
386+ )
387+ const filterFiles = ( tuples ) =>
388+ tuples . filter (
389+ ( [ relativePath , absolutePath ] ) => only . has ( relativePath ) || only . has ( absolutePath )
390+ )
391+ mdToLint = filterFiles ( mdToLint )
392+ ymlToLint = filterFiles ( ymlToLint )
393+ ghesReleaseNotesToLint = filterFiles ( ghesReleaseNotesToLint )
394+ ghaeReleaseNotesToLint = filterFiles ( ghaeReleaseNotesToLint )
395+ learningTracksToLint = filterFiles ( learningTracksToLint )
396+ featureVersionsToLint = filterFiles ( featureVersionsToLint )
397+ }
398+
399+ if (
400+ mdToLint . length +
401+ ymlToLint . length +
402+ ghesReleaseNotesToLint . length +
403+ ghaeReleaseNotesToLint . length +
404+ learningTracksToLint . length +
405+ featureVersionsToLint . length <
406+ 1
407+ ) {
408+ // With this in place, at least one `test()` is called and you don't
409+ // get the `Your test suite must contain at least one test.` error
410+ // from `jest`.
411+ describe ( 'deliberately do nothing' , ( ) => {
412+ test ( 'void' , ( ) => { } )
413+ } )
414+ }
415+
359416describe ( 'lint markdown content' , ( ) => {
360417 if ( mdToLint . length < 1 ) return
361418 describe . each ( mdToLint ) ( '%s' , ( markdownRelPath , markdownAbsPath ) => {
0 commit comments