File xfs.go
has 1127 lines of code (exceeds 500 allowed). Consider refactoring. Open
package xfs
import (
"bytes"
"context"
Method compiler.writeAllocGroup
has 304 lines of code (exceeds 50 allowed). Consider refactoring. Open
func (c *compiler) writeAllocGroup(ctx context.Context, w io.WriteSeeker, ag int64) error {
var err error
allocGroupOffset := ag * c.blocksPerAllocGroup() * c.blockSize()
_, err = w.Seek(allocGroupOffset, io.SeekStart)
Method precompiler.calculateMinimumSize
has a Cognitive Complexity of 74 (exceeds 20 allowed). Consider refactoring. Open
func (p *precompiler) calculateMinimumSize(ctx context.Context) error {
var err error
p.allocGroups = 1
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method compiler.writeAllocGroup
has a Cognitive Complexity of 73 (exceeds 20 allowed). Consider refactoring. Open
func (c *compiler) writeAllocGroup(ctx context.Context, w io.WriteSeeker, ag int64) error {
var err error
allocGroupOffset := ag * c.blocksPerAllocGroup() * c.blockSize()
_, err = w.Seek(allocGroupOffset, io.SeekStart)
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method precompiler.calculateMinimumSize
has 147 lines of code (exceeds 50 allowed). Consider refactoring. Open
func (p *precompiler) calculateMinimumSize(ctx context.Context) error {
var err error
p.allocGroups = 1
Method compiler.popInode
has a Cognitive Complexity of 39 (exceeds 20 allowed). Consider refactoring. Open
func (c *compiler) popInode() io.Reader {
n, more := <-c.nodes
if !more {
return nil
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method compiler.popInode
has 104 lines of code (exceeds 50 allowed). Consider refactoring. Open
func (c *compiler) popInode() io.Reader {
n, more := <-c.nodes
if !more {
return nil
Method compiler.writeAllocGroup
has 34 return statements (exceeds 4 allowed). Open
func (c *compiler) writeAllocGroup(ctx context.Context, w io.WriteSeeker, ag int64) error {
var err error
allocGroupOffset := ag * c.blocksPerAllocGroup() * c.blockSize()
_, err = w.Seek(allocGroupOffset, io.SeekStart)
Method compiler.precompile
has a Cognitive Complexity of 27 (exceeds 20 allowed). Consider refactoring. Open
func (c *compiler) precompile(ctx context.Context) error {
var err error
// alloc group sizes
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method compiler.buildBitmap
has 58 lines of code (exceeds 50 allowed). Consider refactoring. Open
func (c *compiler) buildBitmap() {
c.allocGroupFreeBlocks = make([]int64, c.allocGroups)
c.allocGroupFreeInodes = make([]int64, c.allocGroups)
for i := int64(0); i < c.allocGroups; i++ {
Avoid deeply nested control flow statements. Open
if lfll > p.directoryBlockSize() {
// directory must be stored in node form
x = ddb // data blocks
x += 1 // node block
Avoid deeply nested control flow statements. Open
if err != nil {
panic(err) // NOTE: this is only supported if the filetree supports looking up and caching this value in advance, which should make errors impossible
}
Method precompiler.calculateMinimumSize
has 6 return statements (exceeds 4 allowed). Open
func (p *precompiler) calculateMinimumSize(ctx context.Context) error {
var err error
p.allocGroups = 1
Method precompiler.setBlockSize
has 5 return statements (exceeds 4 allowed). Open
func (p *precompiler) setBlockSize(size int64) error {
if size == 0 {
p.exponents.blockSize = 12 // 4 KiB
return nil
Method compiler.buildBitmap
has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring. Open
func (c *compiler) buildBitmap() {
c.allocGroupFreeBlocks = make([]int64, c.allocGroups)
c.allocGroupFreeInodes = make([]int64, c.allocGroups)
for i := int64(0); i < c.allocGroups; i++ {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method precompiler.Precompile
has 5 return statements (exceeds 4 allowed). Open
func (p *precompiler) Precompile(ctx context.Context, fsSize int64) (*compiler, error) {
var err error
c := &compiler{
TODO found Open
// TODO: var ln int64 // length (node form)
- Exclude checks
TODO found Open
// distribute nodes amongst alloc groups TODO: see if files can be spread out better amongst the alloc groups
- Exclude checks
TODO found Open
panic(errors.New("super nested extents not yet supported")) // TODO
- Exclude checks
TODO found Open
// TODO: improve performance here by treating uint64s instead of bits
- Exclude checks
TODO found Open
c.nodes = make(chan *vio.TreeNode) // TODO: close this safely
- Exclude checks
TODO found Open
recHeader.CycleData[0] = 0xB0C0D0D0 // TODO: figure out what this is supposed to mean.
- Exclude checks
TODO found Open
// TODO: check this (I'm suspicious of the quality of my work when I wrote it)
- Exclude checks
TODO found Open
// TODO: does this work?
- Exclude checks
TODO found Open
Count: uint32(c.inodesPerAllocGroup()), // TODO: - c.allocGroupFreeInodes[ag]), -- is it meant to be this way?
- Exclude checks
TODO found Open
// ExtSize TODO: is this necessary?
- Exclude checks
TODO found Open
// TODO: shuffle entries to optimize used space
- Exclude checks
TODO found Open
c.data = make(chan *vio.TreeNode) // TODO: close this safely
- Exclude checks
TODO found Open
func (c *constants) inodeBlocksPerAllocGroup() int64 { // TODO: unit test if it's possible to get an odd number out of this (I'm suspicious...)
- Exclude checks
TODO found Open
Unknown: 0x6E55, // TODO: Figure out what this is supposed to mean.
- Exclude checks
Identical blocks of code found in 2 locations. Consider refactoring. Open
} else if n.File.IsSymlink() {
// TODO: does this work?
_ = c.computeNodeExtents(n.NodeSequenceNumber, &dataRange{blocks: c.dataReaderBlocksRemaining}) // called here to ensure things are computed in order
c.dataReader = io.MultiReader(n.File, io.LimitReader(vio.Zeroes, c.dataReaderBlocksRemaining*c.blockSize()-int64(n.File.Size())))
} else {
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 101.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Identical blocks of code found in 2 locations. Consider refactoring. Open
} else {
_ = c.computeNodeExtents(n.NodeSequenceNumber, &dataRange{blocks: c.dataReaderBlocksRemaining}) // called here to ensure things are computed in order
c.dataReader = io.MultiReader(n.File, io.LimitReader(vio.Zeroes, c.dataReaderBlocksRemaining*c.blockSize()-int64(n.File.Size())))
}
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 101.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Your code does not pass gofmt in 1 place. Go fmt your code! Open
package xfs
- Exclude checks
should replace x += 1 with x++ Open
x += 1 // node block
- Exclude checks