Update .php handling to keep <?php at the top
Looking at https://www.php.net/manual/en/language.basic-syntax.phptags.php there are just too many variations and I'm not convinced the added complexity to support all of them would be worth it here. Thus, support only the case where closing tag "?>" is either omitted or on a separate line. A workaround for all other cases is to add the license header manually. Can always revisit this later.
This commit is contained in:
3
main.go
3
main.go
@@ -222,7 +222,7 @@ func licenseHeader(path string, tmpl *template.Template, data *copyrightData) ([
|
|||||||
case ".html", ".xml":
|
case ".html", ".xml":
|
||||||
lic, err = prefix(tmpl, data, "<!--", " ", "-->")
|
lic, err = prefix(tmpl, data, "<!--", " ", "-->")
|
||||||
case ".php":
|
case ".php":
|
||||||
lic, err = prefix(tmpl, data, "<?php", "// ", "?>")
|
lic, err = prefix(tmpl, data, "", "// ", "")
|
||||||
case ".ml", ".mli", ".mll", ".mly":
|
case ".ml", ".mli", ".mll", ".mly":
|
||||||
lic, err = prefix(tmpl, data, "(**", " ", "*)")
|
lic, err = prefix(tmpl, data, "(**", " ", "*)")
|
||||||
}
|
}
|
||||||
@@ -242,6 +242,7 @@ var head = []string{
|
|||||||
"<!doctype", // HTML doctype
|
"<!doctype", // HTML doctype
|
||||||
"# encoding:", // Ruby encoding
|
"# encoding:", // Ruby encoding
|
||||||
"# frozen_string_literal:", // Ruby interpreter instruction
|
"# frozen_string_literal:", // Ruby interpreter instruction
|
||||||
|
"<?php", // PHP opening tag
|
||||||
}
|
}
|
||||||
|
|
||||||
func hashBang(b []byte) []byte {
|
func hashBang(b []byte) []byte {
|
||||||
|
|||||||
4
testdata/expected/file.php
vendored
4
testdata/expected/file.php
vendored
@@ -12,6 +12,6 @@
|
|||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
?>
|
|
||||||
|
|
||||||
<?php phpinfo(); ?>
|
namespace App;
|
||||||
|
phpinfo();
|
||||||
|
|||||||
4
testdata/initial/file.php
vendored
4
testdata/initial/file.php
vendored
@@ -1 +1,3 @@
|
|||||||
<?php phpinfo(); ?>
|
<?php
|
||||||
|
namespace App;
|
||||||
|
phpinfo();
|
||||||
|
|||||||
Reference in New Issue
Block a user