Skip to content

Commit c5c82d9

Browse files
committed
fix: Improve license detection
1 parent 4363d7b commit c5c82d9

File tree

1 file changed

+50
-26
lines changed

1 file changed

+50
-26
lines changed

lisp/lint/license.el

Lines changed: 50 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
(locate-dominating-file dir "_prepare.el"))
1515
nil t))
1616

17+
;;
18+
;;; Externals
19+
20+
(require 'whitespace nil t)
21+
1722
;;
1823
;;; Flags
1924

@@ -22,52 +27,71 @@
2227
;;
2328
;;; Core
2429

25-
(defun eask--string-match-all (regexps)
26-
"Return t when every REGEXPS match the `buffer-string'."
27-
(cl-every (lambda (regexp)
28-
(string-match-p regexp (buffer-string)))
29-
regexps))
30+
(defun eask--string-match-all (contents)
31+
"Return t when every CONTENTS match the `buffer-string'."
32+
(cl-every (lambda (content)
33+
(string-match-p (eask-s-replace "\n" " " content) (buffer-string)))
34+
contents))
3035

3136
(defun eask--scan-license (file)
3237
"Scan the license FILE."
33-
(with-current-buffer (find-file file)
38+
(with-temp-buffer
39+
(insert-file-contents file)
40+
(let ((whitespace-style '(trailing)))
41+
(whitespace-cleanup))
42+
(let ((content (eask-s-replace "\n" " " (buffer-string))))
43+
(erase-buffer)
44+
(insert content))
3445
;; See https://api.github.com/licenses
3546
(cond
36-
((eask--string-match-all '("GNU AFFERO GENERAL PUBLIC LICENSE"
37-
"Version 3"
38-
"You should have received a copy of the GNU Affero General Public License"))
47+
((eask--string-match-all
48+
'("You should have received a copy of the GNU Affero General Public License"))
3949
'("agpl-3.0" "GNU Affero General Public License v3.0" "AGPL-3.0"))
40-
((eask--string-match-all '("Apache"
41-
"http://www.apache.org/licenses/"))
50+
((eask--string-match-all
51+
'("Licensed under the Apache License, Version 2.0"))
4252
'("apache-2.0" "Apache License 2.0" "Apache-2.0"))
43-
((eask--string-match-all '("BSD 2-Clause"))
53+
((eask--string-match-all
54+
'("Redistribution and use in source and binary forms"
55+
"Redistributions in binary form must reproduce"))
4456
'("bsd-2-clause" "BSD 2-Clause \"Simplified\" License" "BSD-2-Clause"))
45-
((eask--string-match-all '("BSD 3-Clause"))
57+
((eask--string-match-all
58+
'("Redistribution and use in source and binary forms"
59+
"Neither the name of the copyright holder nor"))
4660
'("bsd-3-clause" "BSD 3-Clause \"New\" or \"Revised\" License" "BSD-3-Clause"))
47-
((eask--string-match-all '("Boost Software License - Version 1.0"))
61+
((eask--string-match-all
62+
'("Permission is hereby granted, free of charge, to any person or organization"))
4863
'("bsl-1.0" "Boost Software License 1.0" "BSL-1.0"))
4964
((eask--string-match-all '("CC0 1.0"))
5065
'("cc0-1.0" "Creative Commons Zero v1.0 Universal" "CC0-1.0"))
51-
((eask--string-match-all '("Eclipse Public License - v 2.0"
52-
"Eclipse Foundation"))
66+
((eask--string-match-all
67+
'("Eclipse Public License - v 2.0"
68+
"Eclipse Foundation"))
5369
'("epl-2.0" "Eclipse Public License 2.0" "EPL-2.0"))
54-
((eask--string-match-all '("GNU General Public License"
55-
"Version 2"))
70+
((eask--string-match-all
71+
'("Copying and distribution of this file, with or without"))
72+
'("fsfap" "FSF All Permissive License" "FSFAP"))
73+
((eask--string-match-all
74+
'("is free software." "you can redistribute it"
75+
"version 2 of the"))
5676
'("gpl-2.0" "GNU General Public License v2.0" "GPL-2.0"))
57-
((eask--string-match-all '("GNU General Public License"
58-
"version 3"
59-
"You should have received a copy of the GNU General Public License"))
77+
((eask--string-match-all
78+
'("is free software." "you can redistribute it"
79+
"version 3 of the"))
6080
'("gpl-3.0" "GNU General Public License v3.0" "GPL-3.0"))
81+
((eask--string-match-all
82+
'("Permission to use, copy, modify, and/or distribute this"))
83+
'("isc" " Internet Systems Consortium" "ISC"))
6184
((eask--string-match-all '("Lesser GPL"
6285
"Version 2.1"))
6386
'("lgpl-2.1" "GNU Lesser General Public License v2.1" "LGPL-2.1"))
64-
((eask--string-match-all '("Permission is hereby granted, free of charge, to any person obtaining a copy"))
87+
((eask--string-match-all
88+
'("Permission is hereby granted, free of charge, to any person"))
6589
'("mit" "MIT License" "MIT"))
66-
((eask--string-match-all '("Mozilla Public License Version 2.0"
67-
"http://mozilla.org/MPL/2.0/"))
90+
((eask--string-match-all
91+
'("http://mozilla.org/MPL/2.0/"))
6892
'("mpl-2.0" "Mozilla Public License 2.0" "MPL-2.0"))
69-
((eask--string-match-all '("This is free and unencumbered software released into the public domain"
70-
"https://unlicense.org"))
93+
((eask--string-match-all
94+
'("This is free and unencumbered software released into"))
7195
'("unlicense" "The Unlicense" "Unlicense"))
7296
(t
7397
'("unknown" "Unknown license" "unknown")))))

0 commit comments

Comments
 (0)