Skip to content

Commit

Permalink
fix: import-order rule
Browse files Browse the repository at this point in the history
  • Loading branch information
dbale-altoros committed Jul 22, 2024
1 parent f7d7126 commit 0b52aaa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
6 changes: 3 additions & 3 deletions e2e/08-autofix/imports-order/Foo1AfterFix.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;

import '@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol';
import 'http://github.com/owner/repo/blob/branch/path/to/Contract2.sol';
import 'https://github.com/owner/repo/blob/branch/path/to/Contract.sol';
import './../../../../token/interfaces/AFakeContract1.sol';
import './../../../../token/interfaces/FakeContract1.sol';
import { FakeContract2 } from './../../../token/interfaces/FakeContract2.sol';
Expand All @@ -16,9 +19,6 @@ import { Initializable } from './openzeppelin/contracts-upgradeable/proxy/utils/
import './Ownable.sol';
import './ThisIsAVeryLongFileOnPurposeToTestTheFirstPathShorterThanTheLastOnelooooooooooong.sol';
import { ReentrancyGuardUpgradeable2 } from '@apenzeppelin/ReentrancyGuardUpgradeable2.sol';
import '@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol';
import 'http://github.com/owner/repo/blob/branch/path/to/Contract2.sol';
import 'https://github.com/owner/repo/blob/branch/path/to/Contract.sol';

contract ImportsOrder {
constructor() {}
Expand Down
12 changes: 7 additions & 5 deletions lib/rules/naming/imports-order.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ const meta = {
],
notes: [
{
note: 'Order by hierarchy of directories first, e.g. ./../../ comes before ./../, which comes before ./, which comes before ./foo',
note: 'Paths starting with "@" like "@openzeppelin/" and urls ("http" and "https") will go first',
},
{
note: 'Paths starting with "@" like "@openzeppelin/" and urls ("http" and "https") will go at last',
note: 'Order by hierarchy of directories first, e.g. ./../../ comes before ./../, which comes before ./, which comes before ./foo',
},
{
note: 'Order alphabetically for each path at the same level, e.g. ./contract/Zbar.sol comes before ./interface/Ifoo.sol',
Expand Down Expand Up @@ -71,6 +71,7 @@ class ImportsOrderChecker extends BaseChecker {
// order the object to get the ordered and the contract order
this.orderedImports = this.sortImports(this.orderedImports)

// console.log('this.orderedImports :>> ', this.fromContractImports)
// console.log('NO Order: \n')
// this.fromContractImports.forEach((importItem) => console.log(importItem.fullSentence))
// console.log('\n\nOrdered: \n')
Expand Down Expand Up @@ -132,10 +133,11 @@ class ImportsOrderChecker extends BaseChecker {
sortImports(unorderedImports) {
// Helper function to determine the hierarchical level of a path
function getHierarchyLevel(path) {
// put very large numbers so these comes first in precedence
const protocolOrder = {
'@': 1,
'http://': 2,
'https://': 3,
'@': -30000,
'http://': -20000,
'https://': -10000,
}

// Check for protocol-specific paths and assign them their respective order levels
Expand Down

0 comments on commit 0b52aaa

Please sign in to comment.