Browse Source

cli: add --skip-lint option (#1482)

Paul 3 years ago
parent
commit
c0b2fd7555

+ 24 - 24
.github/workflows/tests.yaml

@@ -142,7 +142,7 @@ jobs:
           name: anchor-binary
           path: ~/.cargo/bin/
       - run: chmod +rwx ~/.cargo/bin/anchor
-      - run: cd ${{ matrix.node.path }} && anchor build
+      - run: cd ${{ matrix.node.path }} && anchor build --skip-lint
       - uses: actions/upload-artifact@v2
         with:
           name: ${{ matrix.node.name }}
@@ -224,9 +224,9 @@ jobs:
         name: start validator
       - run: cd tests/bpf-upgradeable-state && yarn
       - run: cd tests/bpf-upgradeable-state && yarn link @project-serum/anchor
-      - run: cd tests/bpf-upgradeable-state && anchor build
+      - run: cd tests/bpf-upgradeable-state && anchor build --skip-lint
       - run: cd tests/bpf-upgradeable-state && solana program deploy --program-id program_with_different_programdata.json target/deploy/bpf_upgradeable_state.so
-      - run: cd tests/bpf-upgradeable-state && cp bpf_upgradeable_state-keypair.json target/deploy/bpf_upgradeable_state-keypair.json && anchor deploy && anchor test --skip-deploy --skip-build
+      - run: cd tests/bpf-upgradeable-state && cp bpf_upgradeable_state-keypair.json target/deploy/bpf_upgradeable_state-keypair.json && anchor deploy && anchor test --skip-deploy --skip-build --skip-lint
 
   test-programs:
     needs: setup-anchor-cli
@@ -236,49 +236,49 @@ jobs:
       fail-fast: false
       matrix:
         node:
-          - cmd: cd tests/sysvars && anchor test
+          - cmd: cd tests/sysvars && anchor test --skip-lint
             path: tests/sysvars
-          - cmd: cd tests/composite && anchor test
+          - cmd: cd tests/composite && anchor test --skip-lint
             path: tests/composite
-          - cmd: cd tests/errors && anchor test
+          - cmd: cd tests/errors && anchor test --skip-lint
             path: tests/errors
-          - cmd: cd tests/spl/token-proxy && anchor test
+          - cmd: cd tests/spl/token-proxy && anchor test --skip-lint
             path: spl/token-proxy
-          - cmd: cd tests/multisig && anchor test
+          - cmd: cd tests/multisig && anchor test --skip-lint
             path: tests/multisig
-          - cmd: cd tests/interface && anchor test
+          - cmd: cd tests/interface && anchor test --skip-lint
             path: tests/interface
-          - cmd: cd tests/lockup && anchor test
+          - cmd: cd tests/lockup && anchor test --skip-lint
             path: tests/lockup
-          - cmd: cd tests/swap/deps/serum-dex/dex && cargo build-bpf && cd ../../../ && anchor test
+          - cmd: cd tests/swap/deps/serum-dex/dex && cargo build-bpf && cd ../../../ && anchor test --skip-lint
             path: tests/swap
-          - cmd: cd tests/escrow && anchor test
+          - cmd: cd tests/escrow && anchor test --skip-lint
             path: tests/escrow
-          - cmd: cd tests/pyth && anchor test
+          - cmd: cd tests/pyth && anchor test --skip-lint
             path: tests/pyth
-          - cmd: cd tests/system-accounts && anchor test
+          - cmd: cd tests/system-accounts && anchor test --skip-lint
             path: tests/system-accounts
-          - cmd: cd tests/misc && anchor test
+          - cmd: cd tests/misc && anchor test --skip-lint
             path: tests/misc
-          - cmd: cd tests/events && anchor test
+          - cmd: cd tests/events && anchor test --skip-lint
             path: tests/events
-          - cmd: cd tests/cashiers-check && anchor test
+          - cmd: cd tests/cashiers-check && anchor test --skip-lint
             path: tests/cashiers-check
-          - cmd: cd tests/declare-id && anchor test
+          - cmd: cd tests/declare-id && anchor test --skip-lint
             path: tests/declare-id
-          - cmd: cd tests/typescript && anchor test
+          - cmd: cd tests/typescript && anchor test --skip-lint
             path: tests/typescript
-          - cmd: cd tests/zero-copy && anchor test && cd programs/zero-copy && cargo test-bpf
+          - cmd: cd tests/zero-copy && anchor test --skip-lint && cd programs/zero-copy && cargo test-bpf
             path: tests/zero-copy
-          - cmd: cd tests/chat && anchor test
+          - cmd: cd tests/chat && anchor test --skip-lint
             path: tests/chat
-          - cmd: cd tests/ido-pool && anchor test
+          - cmd: cd tests/ido-pool && anchor test --skip-lint
             path: tests/ido-pool
           - cmd: cd tests/cfo && anchor run test-with-build
             path: tests/cfo
-          - cmd: cd tests/auction-house && yarn && anchor test
+          - cmd: cd tests/auction-house && yarn && anchor test --skip-lint
             path: tests/auction-house
-          - cmd: cd tests/floats && yarn && anchor test
+          - cmd: cd tests/floats && yarn && anchor test --skip-lint
             path: tests/floats
           - cmd: cd tests/safety-checks && ./test.sh
             path: tests/safety-checks

+ 1 - 0
CHANGELOG.md

@@ -15,6 +15,7 @@ incremented for features.
 
 * lang: add check that declared id == program id ([#1451](https://github.com/project-serum/anchor/pull/1451))
 * ts: Added float types support ([#1425](https://github.com/project-serum/anchor/pull/1425)).
+* cli: Add `--skip-lint` option to disable check linting introduced in ([#1452](https://github.com/project-serum/anchor/pull/1452)) for rapid prototyping ([#1482](https://github.com/project-serum/anchor/pull/1482))
 
 ### Fixes
 

+ 1 - 17
cli/src/config.rs

@@ -257,26 +257,10 @@ pub struct Config {
     pub test: Option<Test>,
 }
 
-#[derive(Clone, Debug, Serialize, Deserialize)]
+#[derive(Default, Clone, Debug, Serialize, Deserialize)]
 pub struct FeaturesConfig {
     #[serde(default)]
     pub seeds: bool,
-    #[serde(default = "default_safety_checks")]
-    pub safety_checks: bool,
-}
-
-impl Default for FeaturesConfig {
-    fn default() -> Self {
-        Self {
-            seeds: false,
-            // Anchor safety checks on by default
-            safety_checks: true,
-        }
-    }
-}
-
-fn default_safety_checks() -> bool {
-    true
 }
 
 #[derive(Clone, Debug, Serialize, Deserialize)]

+ 56 - 14
cli/src/lib.rs

@@ -70,6 +70,10 @@ pub enum Command {
         /// Output directory for the IDL.
         #[clap(short, long)]
         idl: Option<String>,
+        /// True if the build should not fail even if there are
+        /// no "CHECK" comments where normally required
+        #[clap(long)]
+        skip_lint: bool,
         /// Output directory for the TypeScript IDL.
         #[clap(short = 't', long)]
         idl_ts: Option<String>,
@@ -151,6 +155,10 @@ pub enum Command {
         /// programs.
         #[clap(long)]
         skip_deploy: bool,
+        /// True if the build should not fail even if there are
+        /// no "CHECK" comments where normally required
+        #[clap(long)]
+        skip_lint: bool,
         /// Flag to skip starting a local validator, if the configured cluster
         /// url is a localnet.
         #[clap(long)]
@@ -250,6 +258,10 @@ pub enum Command {
         /// programs.
         #[clap(long)]
         skip_deploy: bool,
+        /// True if the build should not fail even if there are
+        /// no "CHECK" comments where normally required
+        #[clap(long)]
+        skip_lint: bool,
         /// Arguments to pass to the underlying `cargo build-bpf` command.
         #[clap(
             required = false,
@@ -360,11 +372,13 @@ pub fn entry(opts: Opts) -> Result<()> {
             docker_image,
             bootstrap,
             cargo_args,
+            skip_lint,
         } => build(
             &opts.cfg_override,
             idl,
             idl_ts,
             verifiable,
+            skip_lint,
             program_name,
             solana_version,
             docker_image,
@@ -407,11 +421,13 @@ pub fn entry(opts: Opts) -> Result<()> {
             detach,
             args,
             cargo_args,
+            skip_lint,
         } => test(
             &opts.cfg_override,
             skip_deploy,
             skip_local_validator,
             skip_build,
+            skip_lint,
             detach,
             args,
             cargo_args,
@@ -430,8 +446,15 @@ pub fn entry(opts: Opts) -> Result<()> {
         Command::Localnet {
             skip_build,
             skip_deploy,
+            skip_lint,
+            cargo_args,
+        } => localnet(
+            &opts.cfg_override,
+            skip_build,
+            skip_deploy,
+            skip_lint,
             cargo_args,
-        } => localnet(&opts.cfg_override, skip_build, skip_deploy, cargo_args),
+        ),
     }
 }
 
@@ -685,6 +708,7 @@ pub fn build(
     idl: Option<String>,
     idl_ts: Option<String>,
     verifiable: bool,
+    skip_lint: bool,
     program_name: Option<String>,
     solana_version: Option<String>,
     docker_image: Option<String>,
@@ -736,6 +760,7 @@ pub fn build(
             stdout,
             stderr,
             cargo_args,
+            skip_lint,
         )?,
         // If the Cargo.toml is at the root, build the entire workspace.
         Some(cargo) if cargo.path().parent() == cfg.path().parent() => build_all(
@@ -747,6 +772,7 @@ pub fn build(
             stdout,
             stderr,
             cargo_args,
+            skip_lint,
         )?,
         // Cargo.toml represents a single package. Build it.
         Some(cargo) => build_cwd(
@@ -758,6 +784,7 @@ pub fn build(
             stdout,
             stderr,
             cargo_args,
+            skip_lint,
         )?,
     }
 
@@ -776,6 +803,7 @@ fn build_all(
     stdout: Option<File>, // Used for the package registry server.
     stderr: Option<File>, // Used for the package registry server.
     cargo_args: Vec<String>,
+    skip_lint: bool,
 ) -> Result<()> {
     let cur_dir = std::env::current_dir()?;
     let r = match cfg_path.parent() {
@@ -791,6 +819,7 @@ fn build_all(
                     stdout.as_ref().map(|f| f.try_clone()).transpose()?,
                     stderr.as_ref().map(|f| f.try_clone()).transpose()?,
                     cargo_args.clone(),
+                    skip_lint,
                 )?;
             }
             Ok(())
@@ -811,14 +840,23 @@ fn build_cwd(
     stdout: Option<File>,
     stderr: Option<File>,
     cargo_args: Vec<String>,
+    skip_lint: bool,
 ) -> Result<()> {
     match cargo_toml.parent() {
         None => return Err(anyhow!("Unable to find parent")),
         Some(p) => std::env::set_current_dir(&p)?,
     };
     match build_config.verifiable {
-        false => _build_cwd(cfg, idl_out, idl_ts_out, cargo_args),
-        true => build_cwd_verifiable(cfg, cargo_toml, build_config, stdout, stderr, cargo_args),
+        false => _build_cwd(cfg, idl_out, idl_ts_out, skip_lint, cargo_args),
+        true => build_cwd_verifiable(
+            cfg,
+            cargo_toml,
+            build_config,
+            stdout,
+            stderr,
+            skip_lint,
+            cargo_args,
+        ),
     }
 }
 
@@ -830,6 +868,7 @@ fn build_cwd_verifiable(
     build_config: &BuildConfig,
     stdout: Option<File>,
     stderr: Option<File>,
+    skip_lint: bool,
     cargo_args: Vec<String>,
 ) -> Result<()> {
     // Create output dirs.
@@ -861,7 +900,7 @@ fn build_cwd_verifiable(
         Ok(_) => {
             // Build the idl.
             println!("Extracting the IDL");
-            if let Ok(Some(idl)) = extract_idl(cfg, "src/lib.rs") {
+            if let Ok(Some(idl)) = extract_idl(cfg, "src/lib.rs", skip_lint) {
                 // Write out the JSON file.
                 println!("Writing the IDL file");
                 let out_file = workspace_dir.join(format!("target/idl/{}.json", idl.name));
@@ -1121,6 +1160,7 @@ fn _build_cwd(
     cfg: &WithPath<Config>,
     idl_out: Option<PathBuf>,
     idl_ts_out: Option<PathBuf>,
+    skip_lint: bool,
     cargo_args: Vec<String>,
 ) -> Result<()> {
     let exit = std::process::Command::new("cargo")
@@ -1135,7 +1175,7 @@ fn _build_cwd(
     }
 
     // Always assume idl is located at src/lib.rs.
-    if let Some(idl) = extract_idl(cfg, "src/lib.rs")? {
+    if let Some(idl) = extract_idl(cfg, "src/lib.rs", skip_lint)? {
         // JSON out path.
         let out = match idl_out {
             None => PathBuf::from(".").join(&idl.name).with_extension("json"),
@@ -1192,6 +1232,7 @@ fn verify(
         None,                                                  // idl
         None,                                                  // idl ts
         true,                                                  // verifiable
+        true,                                                  // skip lint
         None,                                                  // program name
         solana_version.or_else(|| cfg.solana_version.clone()), // solana version
         docker_image,                                          // docker image
@@ -1219,7 +1260,7 @@ fn verify(
     }
 
     // Verify IDL (only if it's not a buffer account).
-    if let Some(local_idl) = extract_idl(&cfg, "src/lib.rs")? {
+    if let Some(local_idl) = extract_idl(&cfg, "src/lib.rs", true)? {
         if bin_ver.state != BinVerificationState::Buffer {
             let deployed_idl = fetch_idl(cfg_override, program_id)?;
             if local_idl != deployed_idl {
@@ -1383,17 +1424,12 @@ fn fetch_idl(cfg_override: &ConfigOverride, idl_addr: Pubkey) -> Result<Idl> {
     serde_json::from_slice(&s[..]).map_err(Into::into)
 }
 
-fn extract_idl(cfg: &WithPath<Config>, file: &str) -> Result<Option<Idl>> {
+fn extract_idl(cfg: &WithPath<Config>, file: &str, skip_lint: bool) -> Result<Option<Idl>> {
     let file = shellexpand::tilde(file);
     let manifest_from_path = std::env::current_dir()?.join(PathBuf::from(&*file).parent().unwrap());
     let cargo = Manifest::discover_from_path(manifest_from_path)?
         .ok_or_else(|| anyhow!("Cargo.toml not found"))?;
-    anchor_syn::idl::file::parse(
-        &*file,
-        cargo.version(),
-        cfg.features.seeds,
-        cfg.features.safety_checks,
-    )
+    anchor_syn::idl::file::parse(&*file, cargo.version(), cfg.features.seeds, !skip_lint)
 }
 
 fn idl(cfg_override: &ConfigOverride, subcmd: IdlCommand) -> Result<()> {
@@ -1686,7 +1722,7 @@ fn idl_parse(
     out_ts: Option<String>,
 ) -> Result<()> {
     let cfg = Config::discover(cfg_override)?.expect("Not in workspace.");
-    let idl = extract_idl(&cfg, &file)?.ok_or_else(|| anyhow!("IDL not parsed"))?;
+    let idl = extract_idl(&cfg, &file, true)?.ok_or_else(|| anyhow!("IDL not parsed"))?;
     let out = match out {
         None => OutFile::Stdout,
         Some(out) => OutFile::File(PathBuf::from(out)),
@@ -1726,11 +1762,13 @@ enum OutFile {
 }
 
 // Builds, deploys, and tests all workspace programs in a single command.
+#[allow(clippy::too_many_arguments)]
 fn test(
     cfg_override: &ConfigOverride,
     skip_deploy: bool,
     skip_local_validator: bool,
     skip_build: bool,
+    skip_lint: bool,
     detach: bool,
     extra_args: Vec<String>,
     cargo_args: Vec<String>,
@@ -1743,6 +1781,7 @@ fn test(
                 None,
                 None,
                 false,
+                skip_lint,
                 None,
                 None,
                 None,
@@ -2667,6 +2706,7 @@ fn publish(
         None,
         None,
         true,
+        false,
         Some(program_name),
         None,
         None,
@@ -2754,6 +2794,7 @@ fn localnet(
     cfg_override: &ConfigOverride,
     skip_build: bool,
     skip_deploy: bool,
+    skip_lint: bool,
     cargo_args: Vec<String>,
 ) -> Result<()> {
     with_workspace(cfg_override, |cfg| {
@@ -2764,6 +2805,7 @@ fn localnet(
                 None,
                 None,
                 false,
+                skip_lint,
                 None,
                 None,
                 None,

+ 1 - 1
examples/tutorial/basic-0/package.json

@@ -14,6 +14,6 @@
     "node": ">=11"
   },
   "scripts": {
-    "test": "anchor test"
+    "test": "anchor test --skip-lint"
   }
 }

+ 1 - 1
examples/tutorial/basic-1/package.json

@@ -14,6 +14,6 @@
     "node": ">=11"
   },
   "scripts": {
-    "test": "anchor test"
+    "test": "anchor test --skip-lint"
   }
 }

+ 1 - 1
examples/tutorial/basic-2/package.json

@@ -14,6 +14,6 @@
     "node": ">=11"
   },
   "scripts": {
-    "test": "anchor test"
+    "test": "anchor test --skip-lint"
   }
 }

+ 1 - 1
examples/tutorial/basic-3/package.json

@@ -14,6 +14,6 @@
     "node": ">=11"
   },
   "scripts": {
-    "test": "anchor test"
+    "test": "anchor test --skip-lint"
   }
 }

+ 1 - 1
examples/tutorial/basic-4/package.json

@@ -14,6 +14,6 @@
     "node": ">=11"
   },
   "scripts": {
-    "test": "anchor test"
+    "test": "anchor test --skip-lint"
   }
 }

+ 1 - 1
tests/auction-house

@@ -1 +1 @@
-Subproject commit 52c43eb392580bb333940c73d18971131070098e
+Subproject commit 63e7bb81beb76f2722245a37c16a7b0b00d6905a

+ 0 - 1
tests/cashiers-check/Anchor.toml

@@ -9,4 +9,3 @@ cashiers_check = "Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS"
 test = "yarn run mocha -t 1000000 tests/"
 
 [features]
-safety_checks = false

+ 4 - 5
tests/cfo/Anchor.toml

@@ -12,15 +12,15 @@ lockup = { address = "6ebQNeTPZ1j7k3TtkCCtEPRvG7GQsucQrZ7sSEDQi9Ks", idl = "./de
 # Testing.
 #
 test = "yarn run mocha -t 1000000 tests/"
-test-with-build = "anchor run build && anchor test --skip-build"
+test-with-build = "anchor run build && anchor test --skip-build --skip-lint"
 #
 # Build the program and all CPI dependencies.
 #
-build = "anchor run build-deps && anchor build"
+build = "anchor run build-deps && anchor build --skip-lint"
 build-deps = "anchor run build-dex && anchor run build-swap && anchor run build-stake"
 build-dex = "pushd deps/serum-dex/dex/ && cargo build-bpf && popd"
-build-swap = "cd deps/swap && pwd && anchor build && cd ../../"
-build-stake = "pushd deps/stake && anchor build && popd"
+build-swap = "cd deps/swap && pwd && anchor build --skip-lint && cd ../../"
+build-stake = "pushd deps/stake && anchor build --skip-lint && popd"
 #
 # Runs a localnet with all the programs deployed.
 #
@@ -43,4 +43,3 @@ address = "6ebQNeTPZ1j7k3TtkCCtEPRvG7GQsucQrZ7sSEDQi9Ks"
 program = "./deps/stake/target/deploy/lockup.so"
 
 [features]
-safety_checks = false

+ 1 - 1
tests/cfo/deps/stake

@@ -1 +1 @@
-Subproject commit 571f2c2781e2988da213187d92869613d1ee9c69
+Subproject commit 6a1c128e859b13b39812c0c75d202b2bf9ee1e8c

+ 1 - 1
tests/cfo/deps/swap

@@ -1 +1 @@
-Subproject commit d21838f04360502272490ff2e3a387326579aa6d
+Subproject commit 3da36aaae7af6ce901d68c0280aac34817fe7fd8

+ 0 - 1
tests/chat/Anchor.toml

@@ -9,4 +9,3 @@ chat = "Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS"
 test = "yarn run mocha -t 1000000 tests/"
 
 [features]
-safety_checks = false

+ 0 - 1
tests/custom-coder/Anchor.toml

@@ -13,4 +13,3 @@ wallet = "~/.config/solana/id.json"
 test = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts"
 
 [features]
-safety_checks = false

+ 0 - 1
tests/errors/Anchor.toml

@@ -9,4 +9,3 @@ errors = "Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS"
 test = "yarn run mocha -t 1000000 tests/"
 
 [features]
-safety_checks = false

+ 0 - 1
tests/escrow/Anchor.toml

@@ -9,4 +9,3 @@ escrow = "Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS"
 test = "yarn run ts-mocha -t 1000000 tests/*.ts"
 
 [features]
-safety_checks = false

+ 0 - 1
tests/ido-pool/Anchor.toml

@@ -9,4 +9,3 @@ ido_pool = "Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS"
 test = "yarn run mocha -t 1000000 tests/"
 
 [features]
-safety_checks = false

+ 0 - 1
tests/interface/Anchor.toml

@@ -10,4 +10,3 @@ counter_auth = "Aws2XRVHjNqCUbMmaU245ojT2DBJFYX58KVo2YySEeeP"
 test = "yarn run mocha -t 1000000 tests/"
 
 [features]
-safety_checks = false

+ 0 - 1
tests/lockup/Anchor.toml

@@ -10,4 +10,3 @@ registry = "HmbTLCmaGvZhKnn1Zfa1JVnp7vkMV4DYVxPLWBVoN65L"
 test = "yarn run mocha -t 1000000 tests/"
 
 [features]
-safety_checks = false

+ 0 - 1
tests/multisig/Anchor.toml

@@ -9,4 +9,3 @@ multisig = "Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS"
 test = "yarn run mocha -t 1000000 tests/"
 
 [features]
-safety_checks = false

+ 0 - 1
tests/pda-derivation/Anchor.toml

@@ -1,6 +1,5 @@
 [features]
 seeds = true
-safety_checks = false
 
 [provider]
 cluster = "localnet"

+ 0 - 1
tests/pyth/Anchor.toml

@@ -9,4 +9,3 @@ pyth = "Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS"
 test = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts"
 
 [features]
-safety_checks = false

+ 0 - 1
tests/spl/token-proxy/Anchor.toml

@@ -9,4 +9,3 @@ token_proxy = "Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS"
 test = "yarn run mocha -t 1000000 tests/"
 
 [features]
-safety_checks = false

+ 0 - 1
tests/swap/Anchor.toml

@@ -13,4 +13,3 @@ program = "./deps/serum-dex/dex/target/deploy/serum_dex.so"
 test = "yarn run mocha -t 1000000 tests/"
 
 [features]
-safety_checks = false

+ 1 - 1
tests/zero-copy/Anchor.toml

@@ -13,4 +13,4 @@ zero_cpi = "ErjUjtqKE5AGWUsjseSJCVLtddM6rhaMbDqmhzraF9h6"
 zero_copy = "Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS"
 
 [features]
-safety_checks = false
+