Xavier Petit
813dfb5198
|
5 years ago | |
---|---|---|
.. | ||
README.md | 5 years ago | |
rc.go | 5 years ago |
README.md
rc (restrictions checker)
This program analyses a go source file and displays in standard output the imports, functions, array types and loops used without authorization.
By default:
- NO imports and NO built-in functions are allowed.
- NO casting is allowed either.
- Only functions declared inside the source file are allowed.
- All array types are allowed
- Loops are allowed
Flags
- Two flags are defined:
--cast
allows casting to every built-in type.--no-for
prohibits the use offor
loops in the program or function.--no-array
:- Prohibits all array types if no types are specified after the flag.
Ex.
Only array from the type rune and string are prohibit. All other array from built-in types are allowedAll array type in main.go will cause an error message. - Prohibits only the types specified after the flag Ex. ```console _$ ./rc main.go fmt.* github.com/01-edu/z01.PrintRune len --no-array rune string
- Prohibits all array types if no types are specified after the flag.
Ex.
Arguments:
- First Argument:
The program must be executed passing the go source file to be analyze as the first argument
-
The remaining argument (from 2 to ...):
Can be (without any particular order):
-
Allowed imports and functions from a package
<package>.*
for full imports (all functions from that package are allowed)<package>
.<function>
for partial imports (only the function is allowed)<package>
.<function>#amout
for certain amounts (only certain amount os a function is allowed)- Ex:
fmt.*
(all functions fromfmt
are allowed),github.com/01-edu/z01.PrintRune
(onlyz01.PrintRune
is allowed),append#2
(the only amount ofappend
's allowed is 2)
-
Allowed built-in functions
- Use the name of the built-in function
- Ex:
make
,append
,len
. - Allowed casting
- by using the type of casting, ex: for allowing
string
casting, usestring
- Or use the flag
--cast
, to allow every type of casting
-
Import relative packages
- Use the relative path
- Ex:
../piscine
,..
,.
-
Unallow for loops
- Use the flags
--no-for
. - Note: remember to use it before the
--no-array
flag.- ex:
the last line produces undesired behaviors._$ ./rc main.go fmt.* github.com/01-edu/z01.PrintRune len --no-array <...> --no-for
- Use the flags
-
Unallow literals
- Use the flag
--no-lit="{PATTERN}"
- Note:
"{PATTERN}"
must be a valid RegExp.- ex:
_$ ./rc main.go fmt.* github.com/01-edu/z01.PrintRune len --no-array --no-lit=[b-yB-Y]
- Use the flag
-
-
Optional lasts arguments
- The flag
--no-array
must be given as the last argument or to signal that all the arguments after are unallowed array types
- The flag
Usage:
-
To allow the import of the whole
fmt
package,z01.PrintRune
and the built-in functions len in the filemain.go
The imports must be writen exactly the way are writen inside the source code, example:
_$ ./rc main.go fmt.* github.com/01-edu/z01.PrintRune len
-
More examples:
-
import "fmt" is allowed by executing
_$ ./rc sourcefile.go fmt.*
- import "go/parser" is allowed by executing
_$ ./rc sourcefile.go go/parser.*
- import "github.com/01-edu/z01" is allowed by executing
./rc sourcefile.go github.com/01-edu/z01.*
- import "../../../all/tests/go/solutions" is allowed by executing
_$ ./rc sourcefile.go ../../../all/tests/go/solutions
(no
.*
is needed, all the functions from this relative package are allowed) -
allow all type of casting
_$ ./rc sourcefile.go ../../../all/tests/go/solutions/ztail/ztail.go fmt.* github.com/01-edu/z01 os.* strconv.* make len append --cast
- this will allow all type of casting in the file ztail.go
-
to allow just one type of casting
_$ ./rc sourcefile.go ../../../all/tests/go/solutions/ztail/ztail.go fmt.* github.com/01-edu/z01 os.* strconv.* make len append rune
- this will allow
rune
, but notint8
, ...,string
,float32
, ...
- this will allow