@@ -688,7 +688,7 @@ func checkBomSkip(fileJob *FileJob) int {
688688
689689// Reads and processes files from input chan in parallel, and sends results to
690690// output chan
691- func fileProcessorWorker (input chan * FileJob , output chan * FileJob ) {
691+ func ( ctx processorContext ) fileProcessorWorker (input chan * FileJob , output chan * FileJob ) {
692692 var startTime int64
693693 var fileCount int64
694694 var gcEnabled int64
@@ -721,7 +721,7 @@ func fileProcessorWorker(input chan *FileJob, output chan *FileJob) {
721721
722722 if err == nil {
723723 job .Content = content
724- if processFile (job ) {
724+ if ctx . processFile (job ) {
725725 output <- job
726726 }
727727 } else {
@@ -743,7 +743,7 @@ func fileProcessorWorker(input chan *FileJob, output chan *FileJob) {
743743
744744// Process a single file
745745// File must have been read to job.Content already
746- func processFile (job * FileJob ) bool {
746+ func ( ctx processorContext ) processFile (job * FileJob ) bool {
747747 fileStartTime := makeTimestampNano ()
748748
749749 contents := job .Content
@@ -752,14 +752,14 @@ func processFile(job *FileJob) bool {
752752 job .Language = DetermineLanguage (job .Filename , job .Language , job .PossibleLanguages , job .Content )
753753
754754 remapped := false
755- if RemapAll != "" {
756- hardRemapLanguage (job )
755+ if len ( ctx . remap . all ) != 0 {
756+ ctx . hardRemapLanguage (job )
757757 }
758758
759759 // If the type is #! we should check to see if we can identify
760760 if job .Language == SheBang {
761- if RemapUnknown != "" {
762- remapped = unknownRemapLanguage (job )
761+ if len ( ctx . remap . unknown ) != 0 {
762+ remapped = ctx . unknownRemapLanguage (job )
763763 }
764764
765765 // if we didn't remap we then want to see if it's a #! map
@@ -835,36 +835,30 @@ func processFile(job *FileJob) bool {
835835 return true
836836}
837837
838- func hardRemapLanguage (job * FileJob ) bool {
838+ func ( ctx processorContext ) hardRemapLanguage (job * FileJob ) bool {
839839 remapped := false
840- for s := range strings .SplitSeq (RemapAll , "," ) {
841- t := strings .Split (s , ":" )
842- if len (t ) == 2 {
843- cutoff := min (1000 , len (job .Content )) // at most 1000 bytes into the file to look
844-
845- if strings .Contains (string (job .Content [:cutoff ]), t [0 ]) {
846- job .Language = t [1 ]
847- remapped = true
848- printWarnF ("hard remapping: %s to %s" , job .Location , job .Language )
849- }
840+ cutoff := min (1000 , len (job .Content )) // at most 1000 bytes into the file to look
841+
842+ for _ , rule := range ctx .remap .all {
843+ if bytes .Contains (job .Content [:cutoff ], rule .pattern ) {
844+ job .Language = rule .language
845+ remapped = true
846+ printWarnF ("hard remapping: %s to %s" , job .Location , job .Language )
850847 }
851848 }
852849
853850 return remapped
854851}
855852
856- func unknownRemapLanguage (job * FileJob ) bool {
853+ func ( ctx processorContext ) unknownRemapLanguage (job * FileJob ) bool {
857854 remapped := false
858- for s := range strings .SplitSeq (RemapUnknown , "," ) {
859- t := strings .Split (s , ":" )
860- if len (t ) == 2 {
861- cutoff := min (1000 , len (job .Content )) // at most 1000 bytes into the file to look
862-
863- if strings .Contains (string (job .Content [:cutoff ]), t [0 ]) {
864- printWarnF ("unknown remapping: %s to %s" , job .Location , job .Language )
865- job .Language = t [1 ]
866- remapped = true
867- }
855+ cutoff := min (1000 , len (job .Content )) // at most 1000 bytes into the file to look
856+
857+ for _ , rule := range ctx .remap .unknown {
858+ if bytes .Contains (job .Content [:cutoff ], rule .pattern ) {
859+ job .Language = rule .language
860+ remapped = true
861+ printWarnF ("unknown remapping: %s to %s" , job .Location , job .Language )
868862 }
869863 }
870864
0 commit comments