From c5c82d906882c0669d61f21d0cca127d19115aa7 Mon Sep 17 00:00:00 2001 From: JenChieh Date: Fri, 3 Nov 2023 01:06:41 -0700 Subject: [PATCH] fix: Improve license detection --- lisp/lint/license.el | 76 +++++++++++++++++++++++++++++--------------- 1 file changed, 50 insertions(+), 26 deletions(-) diff --git a/lisp/lint/license.el b/lisp/lint/license.el index 52bbff11..2b488057 100644 --- a/lisp/lint/license.el +++ b/lisp/lint/license.el @@ -14,6 +14,11 @@ (locate-dominating-file dir "_prepare.el")) nil t)) +;; +;;; Externals + +(require 'whitespace nil t) + ;; ;;; Flags @@ -22,52 +27,71 @@ ;; ;;; Core -(defun eask--string-match-all (regexps) - "Return t when every REGEXPS match the `buffer-string'." - (cl-every (lambda (regexp) - (string-match-p regexp (buffer-string))) - regexps)) +(defun eask--string-match-all (contents) + "Return t when every CONTENTS match the `buffer-string'." + (cl-every (lambda (content) + (string-match-p (eask-s-replace "\n" " " content) (buffer-string))) + contents)) (defun eask--scan-license (file) "Scan the license FILE." - (with-current-buffer (find-file file) + (with-temp-buffer + (insert-file-contents file) + (let ((whitespace-style '(trailing))) + (whitespace-cleanup)) + (let ((content (eask-s-replace "\n" " " (buffer-string)))) + (erase-buffer) + (insert content)) ;; See https://api.github.com/licenses (cond - ((eask--string-match-all '("GNU AFFERO GENERAL PUBLIC LICENSE" - "Version 3" - "You should have received a copy of the GNU Affero General Public License")) + ((eask--string-match-all + '("You should have received a copy of the GNU Affero General Public License")) '("agpl-3.0" "GNU Affero General Public License v3.0" "AGPL-3.0")) - ((eask--string-match-all '("Apache" - "http://www.apache.org/licenses/")) + ((eask--string-match-all + '("Licensed under the Apache License, Version 2.0")) '("apache-2.0" "Apache License 2.0" "Apache-2.0")) - ((eask--string-match-all '("BSD 2-Clause")) + ((eask--string-match-all + '("Redistribution and use in source and binary forms" + "Redistributions in binary form must reproduce")) '("bsd-2-clause" "BSD 2-Clause \"Simplified\" License" "BSD-2-Clause")) - ((eask--string-match-all '("BSD 3-Clause")) + ((eask--string-match-all + '("Redistribution and use in source and binary forms" + "Neither the name of the copyright holder nor")) '("bsd-3-clause" "BSD 3-Clause \"New\" or \"Revised\" License" "BSD-3-Clause")) - ((eask--string-match-all '("Boost Software License - Version 1.0")) + ((eask--string-match-all + '("Permission is hereby granted, free of charge, to any person or organization")) '("bsl-1.0" "Boost Software License 1.0" "BSL-1.0")) ((eask--string-match-all '("CC0 1.0")) '("cc0-1.0" "Creative Commons Zero v1.0 Universal" "CC0-1.0")) - ((eask--string-match-all '("Eclipse Public License - v 2.0" - "Eclipse Foundation")) + ((eask--string-match-all + '("Eclipse Public License - v 2.0" + "Eclipse Foundation")) '("epl-2.0" "Eclipse Public License 2.0" "EPL-2.0")) - ((eask--string-match-all '("GNU General Public License" - "Version 2")) + ((eask--string-match-all + '("Copying and distribution of this file, with or without")) + '("fsfap" "FSF All Permissive License" "FSFAP")) + ((eask--string-match-all + '("is free software." "you can redistribute it" + "version 2 of the")) '("gpl-2.0" "GNU General Public License v2.0" "GPL-2.0")) - ((eask--string-match-all '("GNU General Public License" - "version 3" - "You should have received a copy of the GNU General Public License")) + ((eask--string-match-all + '("is free software." "you can redistribute it" + "version 3 of the")) '("gpl-3.0" "GNU General Public License v3.0" "GPL-3.0")) + ((eask--string-match-all + '("Permission to use, copy, modify, and/or distribute this")) + '("isc" " Internet Systems Consortium" "ISC")) ((eask--string-match-all '("Lesser GPL" "Version 2.1")) '("lgpl-2.1" "GNU Lesser General Public License v2.1" "LGPL-2.1")) - ((eask--string-match-all '("Permission is hereby granted, free of charge, to any person obtaining a copy")) + ((eask--string-match-all + '("Permission is hereby granted, free of charge, to any person")) '("mit" "MIT License" "MIT")) - ((eask--string-match-all '("Mozilla Public License Version 2.0" - "http://mozilla.org/MPL/2.0/")) + ((eask--string-match-all + '("http://mozilla.org/MPL/2.0/")) '("mpl-2.0" "Mozilla Public License 2.0" "MPL-2.0")) - ((eask--string-match-all '("This is free and unencumbered software released into the public domain" - "https://unlicense.org")) + ((eask--string-match-all + '("This is free and unencumbered software released into")) '("unlicense" "The Unlicense" "Unlicense")) (t '("unknown" "Unknown license" "unknown")))))