fosslint checks that the structure of free software projects so that they follow a given policy.
A policy can include.
- Which license the project should have, and what header should be applied to all in-scope source files.
- The README mentions how to collaborate.
Install using pip:
$> pip3 install --user fosslint
fosslint
can be invoked without arguments to print any violations that are
present in the current project.
If any violations are present, fosslint
will exit with a non-zero exit status
which is useful if you intend to make it part of your build pipeline.
It is also capable of suggesting a fix for many violations. To do this, run
fosslint --fix
.
$> fosslint --fix
/home/udoprog/repo/project/src/main.c:1 - License Header Mismatch:
" * Copyright (c) 2016 Wrong Entity." != " * Copyright (c) 2016 Right Entity."
--- /home/udoprog/repo/project/src/main.c
+++ /home/udoprog/repo/project/src/main.c.fix
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016 Wrong Entity
+ * Copyright (c) 2016 Right Entity
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +9,7 @@
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
Fix Header [y/n]?
Policies are defined in .fosslint
configuration files that live in the project.
We also look for configuration in the following locations.
/etc/fosslint.conf
$HOME/.fosslint
The configuration file contains sections which match a given file pattern, after which the rule to apply to that kind of file should be defined.
The anonymous section at the top is for global options.
[global]
expect_license = Apache 2.0
entity = Company
year = 2016
[pattern:/**/*.py]
license_header = Apache 2.0
A policy applies a set of default configurations.
The following is an example use of a policy.
[policy:Spotify 1.0]
# configuration
Follows the Spotify FOSS policy, versioned to allow for mistakes.
There is no official guide for this policy.
- Uses
Apache 2.0
as a license. - Makes sure license header is present in non-test source files.
Pattern configurations apply to the file which matches the given glob.
The <glob>
pattern only permits strict matches, where the following rules
apply.
*
matches anything except directory separators.**
matches anything (including nothing)- Only full matches are permitted.
So in order to match any subdirectory in the project that is contained in
a path like src/main
, the following pattern would have to be used:
[pattern:**/src/main/**/*.java]
# configuration
Or if you require at least one subdirectory to be present:
[pattern:/**/*.py]
# configuration
If fosslint can't determine which language a file has, or if the wrong one is detected, this option can override it.
Available languages are:
hash
- Generic language where comments are hash-based (#
prefixed).c-style
- Generic language where comments are c-style (/*
and*/
).python
- Pythonjava
- Java
Expect the license header for the given license to be applied to a file.
Expect the license header in <path>
for all matching source files to be
applied.
This path is relative to the project which is applying the configuration.
This file can contain the following variables, which will be replaced if present:
{entity}
the entity which the license belongs to.{year}
the year for which the license was issued.
Indicates that the beginning of the license header should be padded with the given string.
Typically this is one space (
) by default, but it depends on the extension.
Skip matching any lines in the expected comment header that matches
<linespec>
.
<linespec>
is a line number specification supporting ranges, like 0-10,12
which would match lines 0-10, and 12.
If <string>
is found in any line of the header, do not verify license header.
If true
, will cause trailing spaces in header to be removed.
Any path matched in the ignore section will be ignored by fosslint.
Copyright year to apply.
Automatically determine current year from the local system clock.
If copyright year is a range, this is the first component of that range as in
<start_year>-<year>
.
Expect the given license to be applied to the project.
The format to apply when rendering a year range, must contain {start}
and
{end}
which is replaced with the starting and ending year respectively.
year_range_format = {start}-{end}
The following section describes all the available licenses, and the options that can be applied to them.
Unless apache_notice = no
is set, will check that a /NOTICE
file is present
and contains a copyright notice.
Unless apache_license = no
is set, will check that a /LICENSE
file is
present and contains the entirety of the Apache 2.0 license.