Restore header instead of signature in most syntax files

Turning `header` patterns into `signature` patterns in all syntax files
was a mistake. The two are different things. In almost all syntax files
those patterns are things like shebangs or <?xml ... ?> or
<!DOCTYPE html5> i.e. things that:

1. can be (and should be) used for detecting the filetype when there is
   no `filename` match (and that is actually the purpose of those
   patterns, so it's a regression that it doesn't work anymore).

2. should only occur in the first line of the file, not in the first
   100 lines or so.

In other words, the old `header` semantics was exactly what was needed
for those filetypes, while the new `signature` semantics makes little
sense for them.

So replace `signature` back with `header` in most syntax files. Keep
`signature` only in C++ and Objective-C syntax files, for which it was
actually introduced.
This commit is contained in:
Dmytro Maluka 2024-03-23 21:44:27 +01:00
parent 5492d30953
commit b2a428f1cd
30 changed files with 30 additions and 30 deletions

View File

@ -5,7 +5,7 @@ filetype: powershell
detect:
filename: "\\.ps(1|m1|d1)$"
#signature: ""
#header: ""
rules:
# - comment.block: # Block Comment

View File

@ -2,7 +2,7 @@ filetype: awk
detect:
filename: "\\.awk$"
signature: "^#!.*bin/(env +)?awk( |$)"
header: "^#!.*bin/(env +)?awk( |$)"
rules:
- preproc: "\\$[A-Za-z0-9_!@#$*?\\-]+"

View File

@ -2,7 +2,7 @@ filetype: batch
detect:
filename: "(\\.bat$|\\.cmd$)"
# signature: ""
# header: ""
rules:
# Numbers

View File

@ -2,7 +2,7 @@ filetype: crontab
detect:
filename: "crontab$"
signature: "^#.*?/etc/crontab"
header: "^#.*?/etc/crontab"
rules:
# The time and date fields are:

View File

@ -1,7 +1,7 @@
filetype: csharp-script
detect:
filename: "\\.csx$"
signature: "^#!.*/(env +)?dotnet-script( |$)"
header: "^#!.*/(env +)?dotnet-script( |$)"
rules:
- include: "csharp"

View File

@ -2,7 +2,7 @@ filetype: fish
detect:
filename: "\\.fish$"
signature: "^#!.*/(env +)?fish( |$)"
header: "^#!.*/(env +)?fish( |$)"
rules:
# Numbers

View File

@ -5,7 +5,7 @@ filetype: godoc
detect:
filename: "\\.godoc$"
signature: package.*import
header: package.*import
rules:
- preproc: "^[^ ].*"

View File

@ -2,7 +2,7 @@ filetype: groovy
detect:
filename: "(\\.(groovy|gy|gvy|gsh|gradle)$|^[Jj]enkinsfile$)"
signature: "^#!.*/(env +)?groovy *$"
header: "^#!.*/(env +)?groovy *$"
rules:
# And the style guide for constants is CONSTANT_CASE

View File

@ -2,7 +2,7 @@ filetype: html4
detect:
filename: "\\.htm[l]?4$"
signature: "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN|http://www.w3.org/TR/html4/strict.dtd\">"
header: "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN|http://www.w3.org/TR/html4/strict.dtd\">"
rules:
- error: "<[^!].*?>"

View File

@ -2,7 +2,7 @@ filetype: html5
detect:
filename: "\\.htm[l]?5$"
signature: "<!DOCTYPE html5>"
header: "<!DOCTYPE html5>"
rules:
- error: "<[^!].*?>"

View File

@ -2,7 +2,7 @@ filetype: javascript
detect:
filename: "(\\.js$|\\.es[5678]?$|\\.mjs$)"
signature: "^#!.*/(env +)?node( |$)"
header: "^#!.*/(env +)?node( |$)"
rules:
- constant.number: "\\b[-+]?([1-9][0-9]*|0[0-7]*|0x[0-9a-fA-F]+)([uU][lL]?|[lL][uU]?)?\\b"

View File

@ -2,7 +2,7 @@ filetype: json
detect:
filename: "\\.json$"
signature: "^\\{$"
header: "^\\{$"
rules:
- constant.number: "\\b[-+]?([1-9][0-9]*|0[0-7]*|0x[0-9a-fA-F]+)([uU][lL]?|[lL][uU]?)?\\b"

View File

@ -2,7 +2,7 @@ filetype: julia
detect:
filename: "\\.jl$"
signature: "^#!.*/(env +)?julia( |$)"
header: "^#!.*/(env +)?julia( |$)"
rules:

View File

@ -3,7 +3,7 @@ filetype: 'justfile'
detect:
filename: "(^\\.?[Jj]ustfile|\\.just)$"
signature: "^#!.*/(env +)?[bg]?just --justfile"
header: "^#!.*/(env +)?[bg]?just --justfile"
rules:
- preproc: "\\<(ifeq|ifdef|ifneq|ifndef|else|endif)\\>"

View File

@ -2,7 +2,7 @@ filetype: mail
detect:
filename: "(.*/mutt-.*|\\.eml)$"
signature: "^From .* \\d+:\\d+:\\d+ \\d+"
header: "^From .* \\d+:\\d+:\\d+ \\d+"
rules:
- type: "^From .*"

View File

@ -2,7 +2,7 @@ filetype: makefile
detect:
filename: "([Mm]akefile|\\.ma?k)$"
signature: "^#!.*/(env +)?[bg]?make( |$)"
header: "^#!.*/(env +)?[bg]?make( |$)"
rules:
- preproc: "\\<(ifeq|ifdef|ifneq|ifndef|else|endif)\\>"

View File

@ -2,7 +2,7 @@ filetype: nginx
detect:
filename: "nginx.*\\.conf$|\\.nginx$"
signature: "^(server|upstream)[a-z ]*\\{$"
header: "^(server|upstream)[a-z ]*\\{$"
rules:
- preproc: "\\b(events|server|http|location|upstream)[[:space:]]*\\{"

View File

@ -2,7 +2,7 @@ filetype: patch
detect:
filename: "\\.(patch|diff)$"
signature: "^diff"
header: "^diff"
rules:
- brightgreen: "^\\+.*"

View File

@ -2,7 +2,7 @@ filetype: perl
detect:
filename: "\\.p[lmp]$"
signature: "^#!.*/(env +)?perl( |$)"
header: "^#!.*/(env +)?perl( |$)"
rules:
- type: "\\b(accept|alarm|atan2|bin(d|mode)|c(aller|homp|h(dir|mod|op|own|root)|lose(dir)?|onnect|os|rypt)|d(bm(close|open)|efined|elete|ie|o|ump)|e(ach|of|val|x(ec|ists|it|p))|f(cntl|ileno|lock|ork))\\b|\\b(get(c|login|peername|pgrp|ppid|priority|pwnam|(host|net|proto|serv)byname|pwuid|grgid|(host|net)byaddr|protobynumber|servbyport)|([gs]et|end)(pw|gr|host|net|proto|serv)ent|getsock(name|opt)|gmtime|goto|grep|hex|index|int|ioctl|join)\\b|\\b(keys|kill|last|length|link|listen|local(time)?|log|lstat|m|mkdir|msg(ctl|get|snd|rcv)|next|oct|open(dir)?|ord|pack|pipe|pop|printf?|push|q|qq|qx|rand|re(ad(dir|link)?|cv|say|do|name|quire|set|turn|verse|winddir)|rindex|rmdir|s|scalar|seek(dir)?)\\b|\\b(se(lect|mctl|mget|mop|nd|tpgrp|tpriority|tsockopt)|shift|shm(ctl|get|read|write)|shutdown|sin|sleep|socket(pair)?|sort|spli(ce|t)|sprintf|sqrt|srand|stat|study|substr|symlink|sys(call|read|tem|write)|tell(dir)?|time|tr(y)?|truncate|umask)\\b|\\b(un(def|link|pack|shift)|utime|values|vec|wait(pid)?|wantarray|warn|write)\\b"

View File

@ -2,7 +2,7 @@ filetype: python2
detect:
filename: "\\.py2$"
signature: "^#!.*/(env +)?python2$"
header: "^#!.*/(env +)?python2$"
rules:

View File

@ -2,7 +2,7 @@ filetype: python
detect:
filename: "\\.py(3)?$"
signature: "^#!.*/(env +)?python(3)?$"
header: "^#!.*/(env +)?python(3)?$"
rules:
# built-in objects

View File

@ -2,7 +2,7 @@ filetype: ruby
detect:
filename: "\\.(rb|rake|gemspec)$|^(.*[\\/])?(Gemfile|config.ru|Rakefile|Capfile|Vagrantfile|Guardfile|Appfile|Fastfile|Pluginfile|Podfile|\\.?[Bb]rewfile)$"
signature: "^#!.*/(env +)?ruby( |$)"
header: "^#!.*/(env +)?ruby( |$)"
rules:
- comment.bright:

View File

@ -2,7 +2,7 @@ filetype: sage
detect:
filename: "\\.sage$"
signature: "^#!.*/(env +)?sage( |$)"
header: "^#!.*/(env +)?sage( |$)"
rules:

View File

@ -2,7 +2,7 @@ filetype: sed
detect:
filename: "\\.sed$"
signature: "^#!.*bin/(env +)?sed( |$)"
header: "^#!.*bin/(env +)?sed( |$)"
rules:
- symbol.operator: "[|^$.*+]"

View File

@ -24,7 +24,7 @@ filetype: shell
# * bash-fc. (followed by a random string)
detect:
filename: "(\\.(sh|bash|ash|ebuild)$|(\\.bash(rc|_aliases|_functions|_profile)|\\.?profile|Pkgfile|pkgmk\\.conf|rc\\.conf|PKGBUILD|APKBUILD)$|bash-fc\\.)"
signature: "^#!.*/(env +)?(ba)?(a)?(mk)?sh( |$)"
header: "^#!.*/(env +)?(ba)?(a)?(mk)?sh( |$)"
rules:
# Numbers

View File

@ -2,7 +2,7 @@ filetype: systemd
detect:
filename: "\\.(service|socket|timer)$"
signature: "^\\[Unit\\]$"
header: "^\\[Unit\\]$"
rules:
- statement: "^(Accept|After|Alias|AllowIsolate|Also|ANSI_COLOR|_AUDIT_LOGINUID|_AUDIT_SESSION|Backlog|Before|BindIPv6Only|BindsTo|BindToDevice|BlockIOReadBandwidth|BlockIOWeight|BlockIOWriteBandwidth|_BOOT_ID|Broadcast|BUG_REPORT_URL|BusName|Capabilities|CapabilityBoundingSet|CHASSIS|cipher|class|_CMDLINE|CODE_FILE|CODE_FUNC|CODE_LINE|_COMM|Compress|ConditionACPower|ConditionCapability|ConditionDirectoryNotEmpty|ConditionFileIsExecutable|ConditionFileNotEmpty|ConditionHost|ConditionKernelCommandLine|ConditionNull|ConditionPathExists|ConditionPathExistsGlob|ConditionPathIsDirectory|ConditionPathIsMountPoint|ConditionPathIsReadWrite|ConditionPathIsSymbolicLink|ConditionSecurity|ConditionVirtualization|Conflicts|ControlGroup|ControlGroupAttribute|ControlGroupModify|ControlGroupPersistent|controllers|Controllers|CPE_NAME|CPUAffinity|CPUSchedulingPolicy|CPUSchedulingPriority|CPUSchedulingResetOnFork|CPUShares|CrashChVT|CrashShell|__CURSOR|debug|DefaultControllers|DefaultDependencies|DefaultLimitAS|DefaultLimitCORE|DefaultLimitCPU|DefaultLimitDATA|DefaultLimitFSIZE|DefaultLimitLOCKS|DefaultLimitMEMLOCK|DefaultLimitMSGQUEUE|DefaultLimitNICE|DefaultLimitNOFILE|DefaultLimitNPROC|DefaultLimitRSS|DefaultLimitRTPRIO|DefaultLimitRTTIME|DefaultLimitSIGPENDING|DefaultLimitSTACK|DefaultStandardError|DefaultStandardOutput|Description|DeviceAllow|DeviceDeny|DirectoryMode|DirectoryNotEmpty|Documentation|DumpCore|entropy|Environment|EnvironmentFile|ERRNO|event_timeout|_EXE|ExecReload|ExecStart|ExecStartPost|ExecStartPre|ExecStop|ExecStopPost|ExecStopPre|filter|FONT|FONT_MAP|FONT_UNIMAP|ForwardToConsole|ForwardToKMsg|ForwardToSyslog|FreeBind|freq|FsckPassNo|fstab|_GID|Group|GuessMainPID|HandleHibernateKey|HandleLidSwitch|HandlePowerKey|HandleSuspendKey|hash|HibernateKeyIgnoreInhibited|HOME_URL|_HOSTNAME|ICON_NAME|ID|IdleAction|IdleActionSec|ID_LIKE|ID_MODEL|ID_MODEL_FROM_DATABASE|IgnoreOnIsolate|IgnoreOnSnapshot|IgnoreSIGPIPE|InaccessibleDirectories|InhibitDelayMaxSec|init|IOSchedulingClass|IOSchedulingPriority|IPTOS|IPTTL|JobTimeoutSec|JoinControllers|KeepAlive|KEYMAP|KEYMAP_TOGGLE|KillExcludeUsers|KillMode|KillOnlyUsers|KillSignal|KillUserProcesses|LidSwitchIgnoreInhibited|LimitAS|LimitCORE|LimitCPU|LimitDATA|LimitFSIZE|LimitLOCKS|LimitMEMLOCK|LimitMSGQUEUE|LimitNICE|LimitNOFILE|LimitNPROC|LimitRSS|LimitRTPRIO|LimitRTTIME|LimitSIGPENDING|LimitSTACK|link_priority|valueListenDatagram|ListenFIFO|ListenMessageQueue|ListenNetlink|ListenSequentialPacket|ListenSpecial|ListenStream|LogColor|LogLevel|LogLocation|LogTarget|luks|_MACHINE_ID|MakeDirectory|Mark|MaxConnections|MaxFileSec|MaxLevelConsole|MaxLevelKMsg|MaxLevelStore|MaxLevelSyslog|MaxRetentionSec|MemoryLimit|MemorySoftLimit|MESSAGE|MESSAGE_ID|MessageQueueMaxMessages|MessageQueueMessageSize|__MONOTONIC_TIMESTAMP|MountFlags|NAME|NAutoVTs|Nice|NonBlocking|NoNewPrivileges|NotifyAccess|OnActiveSec|OnBootSec|OnCalendar|OnFailure|OnFailureIsolate|OnStartupSec|OnUnitActiveSec|OnUnitInactiveSec|OOMScoreAdjust|Options|output|PAMName|PartOf|PassCredentials|PassSecurity|PathChanged|PathExists|PathExistsGlob|PathModified|PermissionsStartOnly|_PID|PIDFile|PipeSize|PowerKeyIgnoreInhibited|PRETTY_HOSTNAME|PRETTY_NAME|Priority|PRIORITY|PrivateNetwork|PrivateTmp|PropagatesReloadTo|pss|RateLimitBurst|RateLimitInterval|ReadOnlyDirectories|ReadWriteDirectories|__REALTIME_TIMESTAMP|ReceiveBuffer|RefuseManualStart|RefuseManualStop|rel|ReloadPropagatedFrom|RemainAfterExit|RequiredBy|Requires|RequiresMountsFor|RequiresOverridable|Requisite|RequisiteOverridable|ReserveVT|ResetControllers|Restart|RestartPreventExitStatus|RestartSec|RootDirectory|RootDirectoryStartOnly|RuntimeKeepFree|RuntimeMaxFileSize|RuntimeMaxUse|RuntimeWatchdogSec|samples|scale_x|scale_y|Seal|SecureBits|_SELINUX_CONTEXT|SendBuffer|SendSIGKILL|Service|ShowStatus|ShutdownWatchdogSec|size|SmackLabel|SmackLabelIPIn|SmackLabelIPOut|SocketMode|Sockets|SourcePath|_SOURCE_REALTIME_TIMESTAMP|SplitMode|StandardError|StandardInput|StandardOutput|StartLimitAction|StartLimitBurst|StartLimitInterval|static_node|StopWhenUnneeded|Storage|string_escape|none|replaceSuccessExitStatus|SupplementaryGroups|SUPPORT_URL|SuspendKeyIgnoreInhibited|SyslogFacility|SYSLOG_FACILITY|SyslogIdentifier|SYSLOG_IDENTIFIER|SyslogLevel|SyslogLevelPrefix|SYSLOG_PID|SystemCallFilter|SYSTEMD_ALIAS|_SYSTEMD_CGROUP|_SYSTEMD_OWNER_UID|SYSTEMD_READY|_SYSTEMD_SESSION|_SYSTEMD_UNIT|_SYSTEMD_USER_UNIT|SYSTEMD_WANTS|SystemKeepFree|SystemMaxFileSize|SystemMaxUse|SysVStartPriority|TCPCongestion|TCPWrapName|timeout|TimeoutSec|TimeoutStartSec|TimeoutStopSec|TimerSlackNSec|Transparent|_TRANSPORT|tries|TTYPath|TTYReset|TTYVHangup|TTYVTDisallocate|Type|_UID|UMask|Unit|User|UtmpIdentifier|VERSION|VERSION_ID|WantedBy|Wants|WatchdogSec|What|Where|WorkingDirectory)="

View File

@ -2,7 +2,7 @@ filetype: tcl
detect:
filename: "\\.tcl$"
signature: "^#!.*/(env +)?tclsh( |$)"
header: "^#!.*/(env +)?tclsh( |$)"
rules:
- statement: "\\b(after|append|array|auto_execok|auto_import|auto_load|auto_load_index|auto_qualify|binary|break|case|catch|cd|clock|close|concat|continue|else|elseif|encoding|eof|error|eval|exec|exit|expr|fblocked|fconfigure|fcopy|file|fileevent|flush|for|foreach|format|gets|glob|global|history|if|incr|info|interp|join|lappend|lindex|linsert|list|llength|load|lrange|lreplace|lsearch|lset|lsort|namespace|open|package|pid|puts|pwd|read|regexp|regsub|rename|return|scan|seek|set|socket|source|split|string|subst|switch|tclLog|tell|time|trace|unknown|unset|update|uplevel|upvar|variable|vwait|while)\\b"

View File

@ -2,7 +2,7 @@ filetype: xml
detect:
filename: "\\.(xml|sgml?|rng|svg|plist)$"
signature: "<\\?xml.*\\?>"
header: "<\\?xml.*\\?>"
rules:
- preproc:

View File

@ -2,7 +2,7 @@ filetype: yaml
detect:
filename: "\\.ya?ml$"
signature: "%YAML"
header: "%YAML"
rules:
- type: "(^| )!!(binary|bool|float|int|map|null|omap|seq|set|str) "

View File

@ -2,7 +2,7 @@ filetype: zsh
detect:
filename: "(\\.zsh$|\\.?(zshenv|zprofile|zshrc|zlogin|zlogout)$)"
signature: "^#!.*/(env +)?zsh( |$)"
header: "^#!.*/(env +)?zsh( |$)"
rules:
## Numbers